Alright - here´s part two!
Now we need to collect all our commands we want to use in our OH integration.
I am using the following API´s:
- Power ON / OFF
- Set Cool Mode
- Set Temperature
- Set Operating Mode
- Status Updates
Of course we want to send commands directly from OH to our AC units. But what if someone is using the AC remote and is changing something or turning it completely on or off?
Therefore we need to check the status regulary and get these informations asweel into OH.
Afterwards we will create python scripts and store them directly on the Openhab server. The python scripts will then be executed using the Exec binding.
So this is how I do it:
ON/OFF:
URL: https://api.smartthings.com/v1/devices/yourDeviceID/commands
Command: [{“component”:“main”,“capability”:“switch”,“command”:“on”}]
COOL MODE: (Cooling, heating, drying, auto,…)
URL: https://api.smartthings.com/v1/devices/yourDeviceID/commands
Command: [{“component”:“main”,“capability”:“airConditionerMode”,“command”:“setAirConditionerMode”,“arguments”: [“cool”]}]"
TEMPERATURE:
URL: same as above
Command: [{“component”:“main”,“capability”:“thermostatCoolingSetpoint”,“command”:“setCoolingSetpoint”,“arguments”: [“23.0”]}]"
OPERATING MODE: (Windfree, Fast, Normal, WindFreeSleep, …)
URL: same as above
Command:
[{“component”:“main”,“capability”:“custom.airConditionerOptionalMode”,“command”:“setAcOptionalMode”, “arguments”:[ ““windFree””]}]
Now the status updates. They only return information to you - e.g. if the device is on or which temperature is set at the AC unit.
STATUS UPDATES:
ON/OFF:
URL: https://api.smartthings.com/v1/devices/yourDeviceID/components/main/capabilities/switch/status
Command: none
TEMPERATURE:
URL: https://api.smartthings.com/v1/devices/yourDeviceID/components/main/capabilities/thermostatCoolingSetpoint/status
Command: none
OPERATING MODE:
URL: https://api.smartthings.com/v1/devices/yourDeviceID/components/main/capabilities/custom.airConditionerOptionalMode/status
Command: none
So if you have all your commands and status updates collected you can begin with the next step.
In my case I converted the Rest API commands with Postman to Python language. You can also use http Binding to achieve this but I decided to go with python.
To do so open the Code snippet (located top right corner) and choose your output format.
Copy this and create the python scripts directly on your OH installation.
I created a folder and adjusted the authorizations so that the user which is running Openhab is able to launch the python scripts: