Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Comfofan Controller
- #
- """
- <plugin key="ComfoFanControl" name="Zehnder Comfofan Controller" version="0.0.1">
- <params>
- <param field="Address" label="Server address" width="300px" required="true" default="192.168.2.2"/>
- <param field="Username" label="Username" default="admin" width="300px"/>
- <param field="Password" label="Password" default="nrf905" width="300px"/>
- </params>
- </plugin>
- """
- import Domoticz
- #import json
- from requests import get
- from requests import post
- class BasePlugin:
- #heartbeat of more thsn 30 secs gives error in domoticz log
- #countbeat is the multiplier of 30 seconds so in this case 900 second between each update of the FAN data
- countBeats=30
- def __init__(self):
- return
- def onStart(self):
- # Enable heartbeat
- Domoticz.Log(Parameters["Address"])
- if len(Devices) < 3:
- Domoticz.Log("Missing devices:(")
- self.createDevices()
- Domoticz.Heartbeat(30)
- def createDevices(self):
- if not (1 in Devices):
- Domoticz.Device(Name="FanSpeed", Unit=1, Type=243, Subtype=19, Image=7, Used=1).Create()
- if not (2 in Devices):
- SelectorNames="|Low|Medium|High|Max"
- SelectorOptions="||||"
- Options={"LevelNames":SelectorNames,
- "LevelActions":SelectorOptions,
- "LevelOffHidden": "true",
- "SelectorStyle": "0"}
- Domoticz.Device(Name="Afzuiging Snelheid", Used=1, Unit=2, TypeName="Selector Switch", Switchtype=18, Image=7, Options=Options).Create()
- Domoticz.Log("Devices created.")
- if not (3 in Devices):
- SelectorNames="|10min|30min|60min"
- SelectorOptions="|||"
- Options={"LevelNames":SelectorNames,
- "LevelActions":SelectorOptions,
- "LevelOffHidden": "true",
- "SelectorStyle": "0"}
- Domoticz.Device(Name="Afzuiging Timer", Used=1, Unit=3, TypeName="Selector Switch", Switchtype=18, Image=13, Options=Options).Create()
- Domoticz.Log("Devices created.")
- def onStop(self):
- Domoticz.Log("Stopping")
- def onHeartbeat(self):
- self.countBeats -= 1
- if self.countBeats > 0:
- return
- else:
- self.countBeats = 30
- Domoticz.Log("Heartbeating...")
- url = 'http://'+Parameters['Address']+'/api/test/fan/querydevice.json'
- x = get(url, auth=(Parameters['Username'], Parameters['Password']))
- # Parameters["Username"]
- # data = json.loads(x.text)
- data = x.json()
- devices = data['devices']
- fanID = list(devices.keys())[0] # get the first fanID, i only have one :)
- fanValues = devices[fanID]
- Domoticz.Log("ID: {0}".format(fanValues['id']))
- Domoticz.Log("Speed: {0}".format(fanValues['speed']))
- Domoticz.Log("Timer: {0}".format(fanValues['timer']))
- Domoticz.Log("Percentage: {0}".format(fanValues['percentage']))
- Domoticz.Log("Voltage: {0}".format(fanValues['voltage']))
- if (1 in Devices):
- Devices[1].Update(nValue = 0,sValue=fanValues['speed'])
- # Devices[2].Update(nValue = 10)
- if (2 in Devices):
- if fanValues['speed'] == 'low':
- curSpeed = '10'
- elif fanValues['speed'] == 'medium':
- curSpeed = '20'
- elif fanValues['speed'] == 'high':
- curSpeed = '30'
- else:
- curSpeed = '40'
- Devices[2].Update(0, curSpeed)
- def onCommand(self, Unit, Command, Level, Hue):
- # Domoticz.Log("onCommand called for Unit " + str(Unit) + ": Parameter '" + str(Command) + "', Level: " + str(Level))
- if Unit == 2:
- if Level == 10:
- # Domoticz.Log("Fan speed set to Low")
- setSpeed = 'low'
- elif Level == 20:
- setSpeed = 'medium'
- elif Level == 30:
- setSpeed = 'high'
- else:
- setSpeed = "max"
- url = 'http://'+Parameters['Address']+'/api/v2/fan/setspeed.json?speed={0}'.format(setSpeed)
- x = get(url, auth=(Parameters['Username'], Parameters['Password']))
- Devices[2].Update(0, str(Level))
- elif Unit == 3:
- if Level == 10:
- setTime = 10
- Domoticz.Log("10 minuten")
- elif Level == 20:
- Domoticz.Log("30 minuten")
- setTime = 30
- else:
- setTime = 60
- Domoticz.Log("60 minuten")
- setSpeed = "max"
- url = 'http://'+Parameters['Address']+'/api/v2/fan/setspeed.json?speed={0}&timer={1}'.format(setSpeed, setTime)
- x = get(url, auth=(Parameters['Username'], Parameters['Password']))
- # Domoticz.Log('{0}'.format(Devices[2].sValue))
- global _plugin
- _plugin = BasePlugin()
- def onStart():
- global _plugin
- _plugin.onStart()
- def onStop():
- global _plugin
- _plugin.onStop()
- def onHeartbeat():
- global _plugin
- _plugin.onHeartbeat()
- def onCommand(Unit, Command, Level, Hue):
- global _plugin
- _plugin.onCommand(Unit, Command, Level, Hue)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement