Read RF with Raspberry PI GPIO Binary Sensor

Do you think it is ok if I see 2 instances of the script scripts/rpi-rf_receive-mqtt running?

Hi! :slight_smile: I’m trying to run the Python script to publish the RF codes to an MQTT topic, but I keep getting this error:

Traceback (most recent call last):
File "rfcodes.py", line 12, in <module>
import paho.mqtt.publish as mqtt
ImportError: No module named 'paho' 

I installed paho-mqtt. Any ideas? Any help would be much appreciated. Thanks! :blush:

Found out the problem. Removing “sudo” while running the command worked. Thanks again for making this script! I’m going to put it to very good use :wink:

I want to turn an RF signal into a mqtt message,
I want every code transmitted from my remote control to have a different topic

  • I followed this guide to install the receiver / transmitter on the raspberry and to read the codes transmitted from my remote control.
    ( https://youtu.be/5UUazFbK-Hg )

  • Then I installed mosquitto by following this guide
    ( https://youtu.be/AsDHEDbyLfg ), before I used mqtt integrated in HA

  • So I installed paho-mqtt with this command
    sudo pip3 install paho-mqtt

  • I modified the code written by “gpbenton” to get a different topic for each key of my remote controls.
    SSH command:
    sudo nano /home/pi/rfrxtomqtt.py
    Code:
    https://pastebin.com/4ELr5GF1

  • I added to the raspberry cron the automatic start of the code with Python
    SSH command:
    sudo crontab -e
    Code at the end of the text:
    @reboot python3 /home/pi/rfrxtomqtt.py &

  • I added to the configuration.yaml file
    Code:

    mqtt:
      broker: 192.168.1.201
      port: 1883
      protocol: 3.1.1
      client_id: home-assistant-1
      username: username_mqtt
      password: password_mqtt           
    switch:
      - platform: mqtt
        name: "Light kitchen RF"
        state_topic: "rf/tonino/3366511"
        command_topic: "rf/tonino/3366511"
        payload_on: "ON"
        payload_off: "OFF"
        optimistic: false
        qos: 0
        retain: true
      - platform: mqtt
        name: "Light bedroom RF"
        state_topic: "rf/tonino/3366512"
        command_topic: "rf/tonino/3366512"
        payload_on: "ON"
        payload_off: "OFF"
        optimistic: false
        qos: 0 
        retain: true 
    
  • I modified automations.yaml to switch the lights on / off and to reset the On / Off states :
    Code:

    - alias: 'turn on light kitchen RF'
      trigger:
        - platform: state
          entity_id: switch.light_kitchen_rf
          from: 'off'
          to: 'on'
      action:
        - service: switch.toggle
          entity_id: switch.light_kitchen
        - delay: '00:00:02'
        - service: switch.turn_off
          entity_id: switch.light_kitchen_rf
    - alias: 'turn on light bedroom RF'
      trigger:
        - platform: state
          entity_id: switch.light_bedroom_rf
          from: 'off'
          to: 'on'
      action:
        - service: switch.toggle
          entity_id: switch.light_bedroom
        - delay: '00:00:02'
        - service: switch.turn_off
          entity_id: switch.light_bedroom_rf
    

… Now I can control the house with a 433Mhz RF remote control, I assign a home function to every button on the remote control (for example, turn the light on in the kitchen).
The first pressure to turn on and the next to turn off.
I hope I have been helpful summarizing the post.

3 Likes

@Jiran is it possible to could explain or post the code you ended up using? :slight_smile:

Hi, rpi-rf_receive-mqtt does the job. It receives codes from RF devices using hardware receiver connected to raspberry. Will try to find the script…

Right, however, i do have the script, but how do you make it run?
I did the exact same as you did. But paho-mqtt, how did you manage to install that?
I cant seem to do it with Putty in the new version of Hassio.

Is it possible you could do a quick walkthrough? :smile: