Giter VIP home page Giter VIP logo

Comments (7)

jchasey avatar jchasey commented on August 23, 2024 2

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.

james-fry avatar james-fry commented on August 23, 2024

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.

ianfiske avatar ianfiske commented on August 23, 2024

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.

james-fry avatar james-fry commented on August 23, 2024

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.

jchasey avatar jchasey commented on August 23, 2024

Yes please feel free to use

from hassio-addons.

messismore avatar messismore commented on August 23, 2024

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.

asifma avatar asifma commented on August 23, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.