Skip to content

Using Dyson Pure Cool Link python library & Serverless framework we implement a simple endpoint to control our Dyson device.

Notifications You must be signed in to change notification settings

t04glovern/aws-serverless-dyson

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Serverless Dyson Control Endpoint

Using Dyson Pure Cool Link python library over MQTT & Serverless framework we implement a simple endpoint to control our Dyson device.

Dyson Quote

Serverless Setup

Setup Serverless

npm install -g serverless
serverless config credentials --provider aws --key <ACCESS KEY ID> --secret <SECRET KEY>

Create the project

mkdir aws-serverless-dyson
cd aws-serverless-dyson
serverless create --template aws-python3 --name aws-serverless-dyson

You will receive the following files created for you

.
├── .gitignore
├── handler.py
└── serverless.yml

Setup Serverless Project

Create the values for your secrets

aws ssm put-parameter --name devopstar-dyson-account-email        --type String --value $dyson_account_email
aws ssm put-parameter --name devopstar-dyson-account-password     --type String --value $dyson_account_password
aws ssm put-parameter --name devopstar-dyson-account-region       --type String --value $dyson_account_region
aws ssm put-parameter --name devopstar-dyson-mqtt-public-endpoint --type String --value $dyson_mqtt_public_endpoint

Note the enties in the serverless.yml file, these will be substituded in for you by Serverless based on the parameters above.

service: aws-serverless-dyson

provider:
  name: aws
  runtime: python3.7
  environment:
    DYSON_EMAIL: ${ssm:devopstar-dyson-account-email}
    DYSON_PASS: ${ssm:devopstar-dyson-account-password}
    DYSON_LANG: ${ssm:devopstar-dyson-account-region}
    DYSON_ENDPOINT: ${ssm:devopstar-dyson-mqtt-public-endpoint}

functions:
  stats:
    handler: handler.stats
    events:
      - http:
          path: stats
          method: get

Dyson Endpoint Setup

Dyson Networking Internal

Python Requirements

serverless plugin install -n serverless-python-requirements

Add the following to the serveress.yml file

plugins:
  - serverless-python-requirements

custom:
  pythonRequirements:
    dockerizePip: non-linux

Deploy

serverless deploy

Invoke Function

You can invoke your deployed functions using the following

# Activate a python envirionment locally
python3 -m venv ./venv
source venv/bin/activate
pip install -r requirements.txt

# Test locally
serverless invoke local -f stats
serverless invoke local -f sleep_timer --data '{ "sleep_timer":5 }'

# Test Deployed version
serverless invoke -f stats
serverless invoke -f sleep_timer --data '{ "sleep_timer":5 }'

Attribution

About

Using Dyson Pure Cool Link python library & Serverless framework we implement a simple endpoint to control our Dyson device.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages