Commit bca57057 authored by Peter-Bernd Otte's avatar Peter-Bernd Otte


parent dad26d9c
......@@ -26,8 +26,10 @@ for k,v in data.items():
logger.error("In senders file, type: "+v['type']+" is not supported.")
senderlast = {}
receiverlast = {} # save this message as the last from this enocean receiver
senderlast = {} #last Message from enocean device
def on_message(client, userdata, message):
global receiverlast
global senderlast
global data
global logger
......@@ -37,14 +39,14 @@ def on_message(client, userdata, message):
splittopic = re.split("/", message.topic)"EnOcean Sender: "+splittopic[1])
senderlast[splittopic[1]] = j # save this message as the last from this enocean receiver
receiverlast[splittopic[1]] = j # save this message as the last from this enocean receiver
if j['type'] == 1:
if j["data"][0] in (0xf6, 0xd5, 0xa5): #Senders ROrg: 1BS vom PTM215, 1BS vom FTK, 4BS
s = "".join('{:02x}'.format(x) for x in j['data'][-5:-1])
s = "".join('{:02x}'.format(x) for x in j['data'][-5:-1]) #Enocean Device ID
retain = True if (data[s]['type'] in ("TFBHSB55", "FBH63", "FSM60B", "FHF", "FTKE", "FTK", "FRW")) else False
dataToSend = {'time':j['time'], 'rssi':j["optData"][-2]} #signal strength
dataToSend = {'time':j['time'], 'rssi':j["optData"][-2], 'type':data[s]['type']} #signal strength
if data[s]['type'] == "TFBHSB55":
dataToSend['volts'] = j["data"][1]/255 * 5.1
dataToSend['lux'] = j["data"][2]/255*510
......@@ -60,12 +62,17 @@ def on_message(client, userdata, message):
if j['data'][2] <= 120: dataToSend['descr'] = "battery empty"
elif data[s]['type'] == "PTM215": #push button
LUT = {0x70:1, 0x50:2, 0x30:3, 0x10:4, 0:0}
LUTwords = {0x70:"top", 0x50:"bottom", 0x30:"topleft", 0x10:"bottomleft", 0:"released"} #top and bottom also "right top/right bottom"
if j['data'][1] in LUT:
dataToSend['v'] = LUT[j['data'][1]]
dataToSend['v'] = 1 if j['data'][1] > 0 else 0
if j['data'][1] > 0: #pressed down
client.publish("homie/enocean/"+data[s]['topic']+'/'+LUTwords[ j['data'][1] ], json.dumps(dataToSend), retain=retain)
else: #released
client.publish("homie/enocean/"+data[s]['topic']+'/'+LUTwords[ senderlast[s]['data'][1] ], json.dumps(dataToSend), retain=retain)
dataToSend['descr'] = LUTwords[j['data'][1]]
dataToSend['v'] = LUT[j['data'][1]] #to be send a few lines later
logger.warning("Value "+str(j['data'][1])+" not in LUT")
LUT = {0x70:"top", 0x50:"bottom", 0x30: "left top", 0x10: "left bottom", 0: "released"} #top and bottom also "right top/bottom"
if j['data'][1] in LUT: dataToSend['descr'] = LUT[j['data'][1]]
elif data[s]['type'] == "FHF": #Window handle sensor
dataToSend['v'] = 0 if j['data'][1]==0xf0 else 1 if j['data'][1]==0xd0 else 2 #LUT explanation see next dict
LUT = {0xf0:"closed", 0xc0: "open", 0xe0: "open", 0xd0: "tilted"}
......@@ -82,8 +89,10 @@ def on_message(client, userdata, message):
dataToSend['volts'] = 0 #returns 0 if battery empty
logger.warning("This enocean type is not yet supported.")
client.publish("homie/enocean/"+data[s]['topic'], json.dumps(dataToSend), retain=retain)
if data[s]['type'] not in ("PTM215"):
client.publish("homie/enocean/"+data[s]['topic'], json.dumps(dataToSend), retain=retain)
senderlast[s] = j #to use the value next time, eg. when the push button is released
......@@ -99,4 +108,4 @@ while True:
client.loop_stop()"Program stopped.")
\ No newline at end of file"Program stopped.")
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment