Read RF with Raspberry PI GPIO Binary Sensor

Did you have a look at this …

Yes and thank you. But this is about another piece of HW. I try to find solution based on raspberry. This shouldn´t t be so hard to do.

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.

1 Like

Oh it would be very nice from you. I use this script. And please, if there is any difference,I would like to use Mosquitto. Thank you very much.

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

pip install paho-mqtt
1 Like

Oh this is really fast :smiley: 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).

Yes, its the python interface into mqtt.

This may be of use to you, depending on what else you have to control…

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

Then to subscribe to a topic in switch.yaml

  - platform: mqtt
    name: "Bedroom Switch"
    state_topic: "home/bedroom/switch1"
    command_topic: "home/bedroom/switch1/set"
    availability_topic: "home/bedroom/switch1/available"
    payload_on: "ON"
    payload_off: "OFF"
    optimistic: false
    qos: 0
    retain: true

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

1 Like

Thanks @keithh666 you are lightning fast as usually :slight_smile: 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?

Isn´t this small bug?

mqttauth = {‘username’:“username”, ‘password’ : “” }

there is space between password and : and “” - should it be?

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.

The code that @gpbenton - Graham did for you publishes to the topic of ‘test’, so taking my example…

- platform: mqtt
    name: "Doorbell"
    state_topic: "test"
    command_topic: "test"
    payload_on: "your rx on code for Doorbell"
    payload_off: "your rx off code for Doorbell"
    optimistic: false
    qos: 0
    retain: true

It works! Thank you so much :smiley:

There is no OFF signal. Let it turn off after xx seconds is possible only using automation?

1 Like

If there is no off signal then do the same as you do for the pir’s and turn it off in the automation :slight_smile:

Your help is really great I think you are the best user of this forum :smiley:
I would like to ask you. Which way do you prefer to run python scripts on the startup? rc.local .bashrc init.d tab or systemd?

I don’t run any scripts on start up except for the odd cron job, but I guess systemd, however I’m not a unix guru I just google alot :smiley:

The official way going forward is systemd, so it is worthwhile learning how to set that up with a .service file.

However I have to admit that I still have a line in rc.local, and I probably won’t change that until I have to.:grinning: