Comments (7)
I've been looking into this and have a working (albeit non-elegant) solution by editing the shell script. There are a few challenges when dealing with multiple sensors.
The HA options assumes just one sensor, so would need to be updated to support multiples sensor protocols being passed. However different protocols have different json payloads and therefore you want to publish each sensor to a different mqtt topic, so really an array of protocols and mqtt topics need to be set.
It gets a bit more difficult however as the json output of rtl_433 weirdly does not include the protocol number. Therefore you have to parse the model string in the json to determine which device the payload refers to and therefore which mqtt topic to publish to.
The end result of this is that I have a working solution with some hardcoded values but which is not general purpose. The key changes are as follows:
PROTOCOL="-R 42 -R 43" # Hardcode as we want multiple protocols
/usr/local/bin/rtl_433 -F json $PROTOCOL | while read line
do
# We don't know from the output which protocol number was received
# However we can extract the device name from json output
DEVICE="$(echo $line | jq --raw-output '.model')"
if [ "$DEVICE" = "HIDEKI TS04 sensor" ]; then
MQTT_TOPIC="home/rtl433/weather"
fi
if [ "$DEVICE" = "Oil watchman" ]; then
MQTT_TOPIC="home/rtl433/oil"
fi
# Publish the json to the appropriate topic
echo $line | /usr/bin/mosquitto_pub -h $MQTT_HOST -u $MQTT_USER -P $MQTT_PASS -i RTL_433 -r -l -t $MQTT_TOPIC
done
Then in HA you simply have a number of mqtt sensors as appropriate triggered from the relevant topics.
from hassio-addons.
Hi Ian.
Very pleased it's working for you.
You ask a very good question, and and raised what is a clear use case for this add-on.
Unfortunately it's not a questions that I can categorically answer since I only currently have a single sensor to test with.
However, it looks like one of the repos I based the add-on on does use multiple sensors (albeit very similar binary door/window sensors).
https://github.com/chriskacerguis/honeywell2mqtt
Chris mentions that his solution is working with HA.
I can see that his mqtt payload contains both a sensor type string (model) and what looks like a unique ID (id), so I assume that he's doing the "clever stuff" in HA.
{
"time" : "2017-08-17 13:18:58",
"model" : "Honeywell Door/Window Sensor",
"id" : 547651,
"channel" : 8,
"event" : 4,
"state" : "closed",
"heartbeat" : "yes"
}
Good luck with any changes you make.
Feel free to submit a PR if you get it working - either to the main script if the change is generic, or as an alternative script if not.
Also maybe reach out on the HA community - I think both the repo owners who I forked are lurking there + maybe someone else already did what you need.
from hassio-addons.
Thank you for the pointers, James. I'll give it a try and keep you posted and also reach out to HA community if I get stuck. Not a big investment for one more of those sensors anyhow. If I find something useful, I'll definitely submit a PR.
from hassio-addons.
Thanks for the detailed response. Hope this helps @ianfiske
I'd be happy to roll it into the add-on (or at least add to the readme)
from hassio-addons.
Yes please feel free to use
from hassio-addons.
I have several devices of the same model so I tried a more general approach. If there is a model or id in the message, it will be appended to the message's path, replacing spaces with underscores.
So
{
"model": "Some device",
"id": 42,
…
}
will send the message to $MQTT_PATH/model/id
.
Setting
logger:
default: warning
logs:
homeassistant.components.mqtt: debug
in configuration.yaml
will let you see the exact path of each device in the log.
I know very little bash, so you might want to have a good look at the changes first, but it works for me: #11
from hassio-addons.
Here is an alternative if you have for example PIR sensors that sends like 50 messages in a row when there is motion. This do loop will make the mqtt pub lag as it needs to loop each line.
Just check if the line was not same as previous line.
PREV_LINE=""
/usr/local/bin/rtl_433 -F json -G | while read LINE
do
# Skip duplicate lines
if [ "$LINE" != "$PREV_LINE" ]; then
DEVICE="$(echo $LINE | jq --raw-output '.model' | tr -s ' ' '_')" # replace ' ' with '_'
DEVICEID="$(echo $LINE | jq --raw-output '.id' | tr -s ' ' '_')"
MQTT_PATH=$MQTT_TOPIC
if [ ${#DEVICE} > 0 ]; then
MQTT_PATH=$MQTT_PATH/"$DEVICE"
fi
if [ ${#DEVICEID} > 0 ]; then
MQTT_PATH=$MQTT_PATH/"$DEVICEID"
fi
# Create file with touch /tmp/rtl_433.log if logging is needed
#[ -w /tmp/rtl_433.log ] && echo $line >> rtl_433.log
echo $LINE | /usr/bin/mosquitto_pub -h $MQTT_HOST -i RTL_433 -l -t $MQTT_PATH
fi
# Set the previous line
PREV_LINE="$LINE"
done
from hassio-addons.
Related Issues (20)
- rtl4332mqtt : Named pipe instead of reconnects? HOT 1
- plugin stops- unable to connect HOT 11
- `frequency` , `gain`, `frequency_offset` not detailed in readme - how to calculate? HOT 9
- Async read stalled, exiting! HOT 28
- Malformed json sent to the mqtt broker ? HOT 2
- Starting up fails HOT 4
- Can not add repo to Supervisor
- USB Claim interface error -6 HOT 1
- Request: Ability to set additional MQTT parameters (RETAIN, QOS, etc)
- unable to get RTL_433 to MQTT Bridge to work with HAssio HOT 1
- Can't get HA to discover mqtt
- New protocols HOT 2
- library librtlsdr.so.0 not dound in /usr/local/bin/rtl_433 RTL-Stick does not get Signals library HOT 3
- Latest Supervisor Update - 2021.02.5 - keeps this add-on from starting HOT 19
- Can't install?
- After Upgrading HA, addon stopped working HOT 4
- usb_open error -1 HOT 3
- s6-overlay-suexec: fatal: can only run as pid 1 HOT 2
- How to - rtl_433 update 23.11
- Wrong project url in ink2mqtt json file
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hassio-addons.