Hi Claudio,
Look like your goal is same as mine. I installed mqtt (mosquitto) in the same pi and got superetherodyne transmitter and receiver.
Anyway below is my code:
- Define binary sensor => binary_sensors.yaml
##########################################
- platform: mqtt
state_topic: “hass/sensor/motion_sensor_1”
name: “Backyard_Light_Motion”
qos: 0
payload_on: “ON”
payload_off: “OFF”
sensor_class: motion
##########################################
2.Create automation =>
###########################################
alias: "Motion backyard light during night time"
trigger:
platform: state
entity_id: binary_sensor.backyard_light_motion
from: "off"
to: "on"
condition:
- condition: time
after: '19:00:00'
before: '5:00:00'
action:
service: script.motion_backyard_light
###########################################
3.Script trigger turn on => motion_backyard_light.yaml
###########################################
sequence:
- service: script.turn_off
data:
entity_id: script.motion_backyard_light_timer
- service: switch.turn_on
data:
entity_id: switch.courtyard_light
- service: script.turn_on
data:
entity_id: script.motion_backyard_light_timer
###########################################
4.Script timer to turn off => motion_backyard_light_timer.yaml
###########################################
sequence:
- delay:
minutes: 1
- service: switch.turn_off
data:
entity_id: switch.courtyard_light
- service: mqtt.publish
data:
topic: “hass/sensor/motion_sensor_1”
payload: “OFF”
retain: “true”
###########################################
5.Install paho-mqtt
pip3 install paho-mqtt
6.rf signal detection (this script need to run all the time): #You need find update your pir motion rf code also, your topic name
#!/usr/bin/env python3
import argparse
import signal
import sys
import time
import logging
import paho.mqtt.publish as publish
auth = {
'username':"admin",
'password':"m@ytao11223344556677"
}
from rpi_rf import RFDevice
rfdevice = None
# pylint: disable=unused-argument
def exithandler(signal, frame):
rfdevice.cleanup()
sys.exit(0)
logging.basicConfig(level=logging.INFO, datefmt='%Y-%m-%d %H:%M:%S',
format='%(asctime)-15s - [%(levelname)s] %(module)s: %(message)s', )
parser = argparse.ArgumentParser(description='Receives a decimal code via a 433/315MHz GPIO device')
parser.add_argument('-g', dest='gpio', type=int, default=27,
help="GPIO pin (Default: 27)")
args = parser.parse_args()
signal.signal(signal.SIGINT, exithandler)
rfdevice = RFDevice(args.gpio)
rfdevice.enable_rx()
timestamp = None
logging.info("Listening for codes on GPIO " + str(args.gpio))
i=0
while True:
if rfdevice.rx_code_timestamp != timestamp:
timestamp = rfdevice.rx_code_timestamp
if str(rfdevice.rx_code) == '4654441':
i = i+1
logging.info("Detect code " + str(rfdevice.rx_code) + " i=" + str(i))
if i == 10:
publish.single("hass/sensor/motion_sensor_1","ON",hostname="localhost", auth=auth)
i = 0
time.sleep(60)
time.sleep(0.01)
rfdevice.cleanup()