Hi,
I just installed mine and have it setup working.
I modified the run.py script that came with the code to include similar to your json command for updating the virtual sensors. E.g. I adjusted with my preferred speed settings and added json update commands to the end of the script. In run.py the fan is only updated with new settings if it detects that the power has been lost. My domoticz is dunning on a different host and i have a rpi that controls the fan. I run a cron job on my rpi that update the sensors in Domoticz every minute in the morning, every 5 minutes during the day and every 10 minutes during the night
It would be interesting to add a correct formula for humidity, lux and air flow values (if such exist). I have not tested that much yet but for sure I can tell that the light value is not lux and the humidity is not RH%
I then have added (just for testing) a switch in Domoticz executing a script:
Code: Select all
cat /opt/src/pycalima/fan_5min.py
from pycalima.Calima import Calima
import json
import requests
CALIMA_MAC = "58:2b:db:01:b0:bb"
CALIMA_ID = "xxxxxxxx"
fan = Calima(CALIMA_MAC, CALIMA_ID)
#fan.setFanSpeedSettings(2100,1000,1000)
#print(fan.getFanSpeedSettings())
#Start fan
fan.setBoostMode(1,975,300)
#fan.setSensorsSensitivity(3,1)
#print(fan.getSensorsSensitivity())
state = str(fan.getStateShort())
fan.disconnect()
print(state)
# Update Domoticz just because I like it...
# Find humidity
pos = state.find("Humidity=")
pos2 = state.find(",",int(pos))
Hum = float(state[pos+9:pos2])/10
Hum = str(Hum)
#Hum = state[pos+9:pos2]
# Find temperature
pos = state.find("Temp=")
pos2 = state.find(",",int(pos))
Temp = state[pos+5:pos2]
# Find light
pos = state.find("Light=")
pos2 = state.find(",",int(pos))
Lux = state[pos+6:pos2]
# Find speed
pos = state.find("RPM=")
pos2 = state.find(",",int(pos))
RPM = state[pos+4:pos2]
Flow = round(0.0125 * float(RPM),1)
httpurl = 'http://192.168.0.3:8080/json.htm?type=command¶m=udevice&idx=135&nvalue=0&svalue=' + Temp + ';' + Hum + ';0'
r = requests.get(httpurl)
httpurl = 'http://192.168.0.3:8080/json.htm?type=command¶m=udevice&idx=136&svalue=' + Lux
r = requests.get(httpurl)
httpurl = 'http://192.168.0.3:8080/json.htm?type=command¶m=udevice&idx=138&nvalue=0&svalue=' + str(Flow)
r = requests.get(httpurl)
httpurl = 'http://192.168.0.3:8080/json.htm?type=command¶m=udevice&idx=137&nvalue=0&svalue=' + str(round(int(RPM)/2400*100,1))
r = requests.get(httpurl)
#Reset switch state
httpurl = 'http://192.168.0.3:8080/json.htm?type=command¶m=udevice&idx=139&svalue=0'
r = requests.get(httpurl)
Script that runs in cron:
Code: Select all
crontab -l
# m h dom mon dow command
#*/5 7,8 * * * python3 /opt/src/pycalima/fan.py
* 7,8 * * * python3 /opt/src/pycalima/fan.py
*/5 9,10,11,12,13,14,15,16,17,18,19,20,21 * * * python3 /opt/src/pycalima/fan.py
*/10 22,0,1,2,3,4,5,6 * * * python3 /opt/src/pycalima/fan.py
Code: Select all
cat fan.py
#!/usr/bin/env python3
import sys, time, datetime, json, requests
from pycalima.Calima import Calima
# Here you can specify your Calimas MAC address and pincode
# Address you can find by using cmdline.poy script and -l parameter
# Pincode is found on the backside of the manual or on one of the
# feet of the motor plug component
fan = Calima("58:2b:db:01:b0:bb", "12234235")
appliedSettings = 0
try:
# print(fan.getAlias())
# print(fan.getState())
# If Clock is not set then there has been a power failure,
# so just in case we will write the settings to Calima and set time
if fan.getIsClockSet() == "02":
# Lets preconfigure Calima by setting these values
# Set appliedSettings to 1 since we are applying the settings
# We then output its value at the bottom so we know if there was a power cycle
appliedSettings = 1
# Start off by setting time and then wait 2 seconds for it to settle before polling for time
fan.setTimeToNow()
time.sleep(2)
#fan.getTime()
# Setting Fan speed, I am not using light sensor therefore same value in fields 2 and 3
fan.setFanSpeedSettings(2100,1100,1000)
# Sets humidity sensivitity and light sensitivity. If set to 0 then sensor triggering will be off
fan.setSensorsSensitivity(3,1)
#fan.getSensorsSensitivity()
# Set Light sensor delay and running times. Just setting these even if I do not use light sensor for now.
fan.setLightSensorSettings(5,5)
#fan.getLightSensorSettings()
# Set automatic purge cycles which is max speed for X minutes every 12 hours, 0=disabled, 1=30min, 2=60min, 3=90min
# Disable it for now as I want to control it from other Smart Home systems
fan.setAutomaticCycles(0)
#fan.getAutomaticCycles()
# Setting Silent hours
fan.setSilentHours(1,22,0,6,0)
#fan.getSilentHours()
# Set trickle days
fan.setTrickleDays(1,1)
#fan.getTrickleDays()
# Need to iterate through namedtuple and print its contents
# concatenating appliedSettings value and prefixing with timestamp without newline
currentState = fan.getStateShort()
timeStamp = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S ')
print(timeStamp,end='')
for item in currentState._fields:
print("{}={} ".format(item,getattr(currentState, item)),end='')
print("appliedSettings={}".format(appliedSettings))
except Exception as e:
print(e)
fan.disconnect()
state = str(currentState)
# Find humidity
pos = state.find("Humidity=")
pos2 = state.find(",",int(pos))
Hum = float(state[pos+9:pos2])/10
Hum = str(Hum)
#Hum = state[pos+9:pos2]
# Find temperature
pos = state.find("Temp=")
pos2 = state.find(",",int(pos))
Temp = state[pos+5:pos2]
# Find light
pos = state.find("Light=")
pos2 = state.find(",",int(pos))
Lux = state[pos+6:pos2]
# Find speed
pos = state.find("RPM=")
pos2 = state.find(",",int(pos))
RPM = state[pos+4:pos2]
Flow = round(0.0125 * float(RPM),1)
httpurl = 'http://192.168.0.3:8080/json.htm?type=command¶m=udevice&idx=135&nvalue=0&svalue=' + Temp + ';' + Hum + ';0'
r = requests.get(httpurl)
httpurl = 'http://192.168.0.3:8080/json.htm?type=command¶m=udevice&idx=136&svalue=' + Lux
r = requests.get(httpurl)
httpurl = 'http://192.168.0.3:8080/json.htm?type=command¶m=udevice&idx=138&nvalue=0&svalue=' + str(Flow)
r = requests.get(httpurl)
httpurl = 'http://192.168.0.3:8080/json.htm?type=command¶m=udevice&idx=137&nvalue=0&svalue=' + str(round(int(RPM)/2400*100,1))
r = requests.get(httpurl)