@keithh666 or other Please could you recommend how to read from GPIO using rpi_gpio?
RXB6 433MHz receiver is connected to raspberry´s GPIO. RF sniffing python script is able to read codes from rf devices. How to get it into home assistant using rpi_gpio?
binary_sensor:
- platform: rpi_gpio
ports:
11: PIR Office
12: PIR Bedroom
However as I assume you have figured out your pir is not directly connected it’s using RF433 so you need a program to decode the RF and send a appropriate message to HA, this is usually done with either some other HW such as RF Link, Telldus, RFXTX or some RF receiver and transmitter directly connect to the PI with either pilight or some other SW decoding the RF to send a message to HA. You could use some other software to decode the RF and use it to toggle the GPIO pins directly but that would not be efficient and you only have so many GPIO’s. If you have the Rx’er and Tx’er attached to the PI then pilight is the best option that I know. If you have some other software sniffing the code from your Rx’er then just modify it to send a MQTT message to HA.
Thanks Keith. I´m right now on the way to try both MQTT and Pilight. I would like to have all on single board (raspberry) so we will see what is better solution. I will need MQTT for other switches so I hope this will be better way for me but seems like there is no direct solution for RF2MQTT on Pi. All I checked till now was based on arduino
if you publish your Python script you use to get the values from RF, I should be able to add the few lines necessary to get it to send an mqtt message.
I cloned that repository and created a script here
If you have a username and password defined in mosquitto, you can change that in line 16. If you don’t (like me), it seems to work just fine as it is.
At the moment, it should just send the code received. If you need the pulselength and proto as well, I can fix that.
Obviously, I can’t test it completely, because I don’t have a receiver, but if it works, let me know and I’ll send a pull request back to the author so he can add it to his scripts.
Edit:
Also, you need to add the mqtt library to your environment
Oh this is really fast Many thanks! I´l ltry it and give you feedback. paho-mqtt is neccesarry even if I have mosquitto? Isn´t it some kind of alternative of mosquitto? (i try to have system as clean as possible).
Does anybody knows hot to correct setup configuration.yaml if mosquitto is running on the same device (raspy3)? In this case home assistant is a broker or a client? I really don= t know hot to get mqtt received codes from rf into HA. Could anyone help?
HA is always a client, the broker is mosquitto… I have my broker mosquitto on a chip (mini linux computer), but the setup in HA is exactly the same as HA is a client so … in HA configuration.yaml
mqtt:
broker: !secret mqtt_broker <---- ip addr of broker i.e. addr of pi that HA is on if broker on same pi
port: !secret mqtt_port <----- 1883
client_id: home-assistant
username: !secret mqtt_usern <------ mosquitto username
password: !secret mqtt_pw <-------- mosquitto pw
keepalive: 60
protocol: 3.1.1
For a check you can use the command line tools mosquitto_pub shipped with mosquitto to send MQTT messages. This allows you to operate your switch manually:
$ mosquitto_pub -h 127.0.0.1 -t home/bedroom/switch1 -m “ON” <-------- you may need to add pw and username see --help
Thanks @keithh666 you are lightning fast as usually You are really helpful. But how do you recommmend to set the “switch”? I used rflink on one of my raspberrys. There were 433 motion sensors connected to rflink and while rflink sent only single code it was OK for switch which I returned back to OFF state via automation.
But how about a 433 ring button which I use now with your rpi-rf_receive-mqtt script? This device makes this with rpi.rf:receive script: [INFO] rpi-rf_receive: 14110972 [pulselength 198, protocol 1]
So many lines how long I hold the button. I think using only rpi-rf_receive-mqtt there will be many lines of the same code. Do you recommend to use switch component - and how?
I don’t think it will matter to HA if you get lots of on messages, but you could modify the python code to only send 1 MQTT message per press of the doorbell. I would have thought the firmware in the doorbell would only send 1 on RF message and 1 off RF message? Does RF Link not work with the Doorbell?
RFlink should work. But rflink is connected on my other device (not in home). At home I have only cheap RXB6 heterodyne RF receiver. Using your script I can receive signals and read them in command line. But please read my post below. I can´t get them into HA using MQTT.