Here are my scripts (sorry for the delay)
One in LUA to manage devices changes in domoticz and one in Python to send command using Sensible API
You will have to create 4 dummy switches by pod
AC STATE switch ON/OFF
AC MODE selectable HEAT/COOL/FAN/AUTO
AC FAN selectable LOW/MEDIUM/HIGH/AUTO
AC TEMPERATURE Temperature
sensibo_client_by_pod.py
I put it in scripts/sensibo folder
make it executable :
No changes needed, if you want to test it just execute it using the following command
Code: Select all
python sensibo_client_by_pod.py yourapikey yourpoduid youracstate youracmode youracfan youractemperature
acstate is on,off ; acmode cool,heat,fan,auto ; acfan low,medium,high,auto ; actemp in a integer in degrees
Code: Select all
import requests
import json
_SERVER = 'https://home.sensibo.com/api/v2'
class SensiboClientAPI(object):
def __init__(self, api_key):
self._api_key = api_key
def _get(self, path, ** params):
params['apiKey'] = self._api_key
response = requests.get(_SERVER + path, params = params)
response.raise_for_status()
return response.json()
def _post(self, path, data, ** params):
params['apiKey'] = self._api_key
response = requests.post(_SERVER + path, params = params, data = data)
response.raise_for_status()
return response.json()
def pod_uids(self):
result = self._get("/users/me/pods")
pod_uids = [x['id'] for x in result['result']]
return pod_uids
def pod_measurement(self, podUid):
result = self._get("/pods/%s/measurements" % podUid)
return result['result']
def pod_ac_state(self, podUid):
result = self._get("/pods/%s/acStates" % podUid, limit = 1, fields="status,reason,acState")
return result['result'][0]
def pod_change_ac_state(self, podUid, on, target_temperature, mode, fan_level):
self._post("/pods/%s/acStates" % podUid,
json.dumps({'acState': {"on": on, "targetTemperature": target_temperature, "mode": mode, "fanLevel": fan_level}}))
if __name__ == "__main__":
import argparse
parser = argparse.ArgumentParser(description='Sensibo client example parser')
parser.add_argument('apikey', type = str)
parser.add_argument('poduid', type = str)
parser.add_argument('--on', action="store_true", default=False, dest='status')
parser.add_argument('--off', action="store_false", default=False, dest='status')
parser.add_argument('temperature', type = int)
parser.add_argument('mode', type = str)
parser.add_argument('fan', type = str)
args = parser.parse_args()
client = SensiboClientAPI(args.apikey)
pod_uids = client.pod_uids()
#print "All pod uids:", ", ".join(pod_uids)
#print "Pod measurement for first pod", client.pod_measurement(pod_uids[0])
#last_ac_state = client.pod_ac_state(pod_uids[0])
#print "Last AC change %(success)s and was caused by %(cause)s" % { 'success': 'was successful' if last_ac_state['status'] == 'Success' else 'failed', 'cause': last_ac_state['reason'] }
#print "and set the ac to %s" % str(last_ac_state['acState'])
client.pod_change_ac_state(args.poduid,args.status,args.temperature,args.mode,args.fan)
print "Pod UID : ", args.poduid
print "Status : ", args.status
print "Temp : ", args.temperature
print "Mode : ", args.mode
print "Fan : ", args.fan
and second script
script_device_sensibo.lua
I put it in scripts/lua folder
You will have to change device names and edit your sensibo api key and pod iud
Code: Select all
-- script name : script_device_sensibo.lua
-- This script will trigger a python script every time a Sensibo settings using Domoticz dummy switchs change status
-- Create virtual selectable switch. e.g. : "AC State (ON/OFF), Mode (HEAT/COOL/FAN/AUTO), Fan (LOW/MEDIUM/HIGH/AUTO), Temperature"
commandArray = {}
apikey = 'yourapikey'
poduid_bedroom = 'yourpoduid'
poduid_kitchen = 'yourpoduid'
for key, value in pairs(devicechanged) do
if (key == 'AC Kitchen' or key == 'Mode Kitchen' or key == 'Fan Kitchen' or key == 'Temp Kitchen') then
poduid = poduid_Kitchen
state = otherdevices['AC Kitchen']:lower()
mode = otherdevices['Mode Kitchen']
fan = otherdevices['Fan Kitchen']
temperature = math.floor(otherdevices_svalues['Temp Kitchen'])
if ((devicechanged['AC Kitchen'] == 'On') or (key == 'AC Kitchen') or (otherdevices['AC Kitchen'] == 'On')) then
os.execute("python /home/pi/domoticz/scripts/sensibo/sensibo_client_by_pod.py "..apikey.." "..poduid.." --"..state.." "..temperature.." "..mode.." "..fan)
--print("python /home/pi/domoticz/scripts/sensibo/sensibo_client_by_pod.py "..apikey.." "..poduid.." --"..state.." "..temperature.." "..mode.." "..fan)
--print("API key : "..apikey..", Pod UID : " ..poduid.. ", State : "..state..", Mode : "..mode..", Fan : "..fan..", Temp : "..temperature)
print("AC Kitchen : "..state..", "..temperature..", "..mode..", "..fan)
end
end
if (key == 'AC Bedroom' or key == 'Mode Bedroom' or key == 'Fan Bedroom' or key == 'Temp Bedroom') then
poduid = poduid_Bedroom
state = otherdevices['AC Bedroom']:lower()
mode = otherdevices['Mode Bedroom']
fan = otherdevices['Fan Bedroom']
temperature = math.floor(otherdevices_svalues['Temp Bedroom'])
if ((devicechanged['AC Bedroom'] == 'On') or (key == 'AC Bedroom') or (otherdevices['AC Bedroom'] == 'On')) then
os.execute("python /home/pi/domoticz/scripts/sensibo/sensibo_client_by_pod.py "..apikey.." "..poduid.." --"..state.." "..temperature.." "..mode.." "..fan)
--print("python /home/pi/domoticz/scripts/sensibo/sensibo_client_by_pod.py "..apikey.." "..poduid.." --"..state.." "..temperature.." "..mode.." "..fan)
--print("API key : "..apikey..", Pod UID : " ..poduid.. ", State : "..state..", Mode : "..mode..", Fan : "..fan..", Temp : "..temperature)
print("AC Bedroom : "..state..", "..temperature..", "..mode..", "..fan)
end
end
end
return commandArray
Hope this code helps people here
I'm not a coder so if you want to improve the scripts you're welcome