Created
August 2, 2022 12:28
-
-
Save dernorberto/13d1f9e3746932444cef8510b7957025 to your computer and use it in GitHub Desktop.
RF door sensor MQTT demultiplexing/demux using a python script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## based on https://community.home-assistant.io/t/sonoff-rf-bridge-strategies-for-receiving-data/108181 | |
# | |
## Script to demux cheap RF door/window sensors into additional topics for each sensor. | |
# | |
## Original MQTT message to demux | |
## ============================== | |
## topic: rtl_433/Cardin-S466 | |
## payload: | |
## { | |
## "time": "2022-07-21T06:19:47Z", | |
## "model": "Cardin-S466", | |
## "dipswitch": "--+--o+++", | |
## "rbutton": "10R" | |
## } | |
d = { '-o-+-oo-o':['sensor01','true'], | |
'--+--o+++':['sensor02','true'], | |
'o++--o--o':['sensor03','true'], | |
'--o--o-+-':['sensor04','true'] | |
} | |
e = { '10R':['on'], | |
'00L?':['off'] | |
} | |
p = data.get('payload') # I must keep the dict and not str() convert it | |
p1 = p['dipswitch'] | |
p2 = p['rbutton'] | |
if p is not None: | |
if p1 in d.keys(): | |
service_data = {'topic':'rtl_433/Cardin-S466/{}'.format(d[p1][0]), 'payload':"{}".format(e[p2][0]), 'qos':1, 'retain':"{}".format(d[p1][1])} | |
elif p1 == "": | |
service_data = {'topic':'rtl_433/Cardin-S466/blank', 'payload':'{}'.format(p), 'qos':1, 'retain':'false'} | |
else: | |
service_data = {'topic':'rtl_433/Cardin-S466/unknown', 'payload':'{}'.format(p).str() , 'qos':1, 'retain':'false'} | |
logger.warning('<rfbridge_demux> Received unknown RF command: {}'.format(p)) | |
hass.services.call('mqtt', 'publish', service_data, False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## This content is part of the mqtt.yaml file | |
# | |
# MQTT topics created by demux python script | |
# | |
# Garage Side Door | |
- unique_id: 'door_garagesidedoor' | |
name: 'Garage Side Door' | |
device_class: 'door' | |
state_topic: 'rtl_433/Cardin-S466/sensor01' | |
value_template: '{{ value }}' | |
payload_on: 'off' | |
payload_off: 'on' | |
# Front Door | |
- unique_id: 'door_frontdoor' | |
name: 'Front Door' | |
device_class: 'door' | |
state_topic: 'rtl_433/Cardin-S466/sensor02' | |
value_template: '{{ value }}' | |
payload_on: 'off' | |
payload_off: 'on' | |
# Garage Left Door | |
- unique_id: 'door_garageleftdoor' | |
name: 'Garage Door Left' | |
device_class: 'door' | |
state_topic: 'rtl_433/Cardin-S466/sensor03' | |
value_template: '{{ value }}' | |
payload_on: 'off' | |
payload_off: 'on' | |
# Garage Right Door | |
- unique_id: 'door_garagerightdoor' | |
name: 'Garage Door Right' | |
device_class: 'door' | |
state_topic: 'rtl_433/Cardin-S466/sensor04' | |
value_template: '{{ value }}' | |
payload_on: 'off' | |
payload_off: 'on' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment