Hi, I finally received a receiver that works. Evidently my first receiver was defective … damn.
Trying your config now
Hi, I finally received a receiver that works. Evidently my first receiver was defective … damn.
Trying your config now
how to make it run from boot, all time?
I receive this error, shall I do something about it?
pi@raspberrypi:~ $ sudo python3 rf_receive.py
/usr/local/lib/python3.4/dist-packages/rpi_rf/rpi_rf.py:167: RuntimeWarning: Thi s channel is already in use, continuing anyway. Use GPIO.setwarnings(False) to disable warnings.
GPIO.setup(self.gpio, GPIO.IN)
2017-04-02 14:07:34 - [INFO] rf_receive: Listening for codes on GPIO 27
2017-04-02 14:09:15 - [INFO] rf_receive: Detect code 971897 i=1
2017-04-02 14:09:15 - [INFO] rf_receive: Detect code 971897 i=2
I want to trigger a light.foyer on when motion sensor is activated. Is working but light does not turn off after one minute??
Other question, what is needed the first script.turn_off for?
# Script motion
motion_foyer_light:
sequence:
- service: script.turn_off
data:
entity_id: script.motion_foyer_light_timer
- service: light.turn_on
data:
entity_id: light.foyer
- service: script.turn_on
data:
entity_id: script.motion_foyer_light_timer
motion_foyer_light_timer:
sequence:
- delay:
minutes: 1
- service: light.turn_off
data:
entity_id: light.foyer
- service: mqtt.publish
data:
topic: "hass/sensor/pir_entrance_one"
payload: "OFF"
retain: "true"
I successfully manage to learn codes for a receiver (PIR sensor) and put it in a rf_receive.py file
How to make this file run at boot all time?
You can follow the instructions in this link: http://www.raspberrypi-spy.co.uk/2013/07/running-a-python-script-at-boot-using-cron/
Thanks, now I have this, is it ok?
pi@raspberrypi:~ $ ps aux | grep /home/pi/rf_receive.py
root 486 13.5 1.1 24652 11112 ? Sl 18:53 0:34 python3 /home/p i/rf_receive.py
pi 2384 0.0 0.2 4280 1912 pts/0 S+ 18:57 0:00 grep --color=au to /home/pi/rf_receive.py
pi@raspberrypi:~ $
Sensor goes from off to on, but not from on to off, can someone explain why?
This is the configuration
binary_sensor pir_entrance1:
- platform: mqtt
state_topic: "/home/hass/.homeassistant/sensor/pir_entrance_one"
name: "Foyer Light Motion"
qos: 0
payload_on: "ON"
payload_off: "OFF"
sensor_class: motion
# Script motion
motion_foyer_light:
sequence:
#- service: script.turn_off
# data:
# entity_id: script.motion_foyer_light_timer
- service: light.turn_on
data:
entity_id: light.foyer
- service: script.turn_on
data:
entity_id: script.motion_foyer_light_timer
motion_foyer_light_timer:
sequence:
- delay:
minutes: 1
- service: light.turn_off
data:
entity_id: light.foyer
- service: mqtt.publish
data:
topic: "/home/hass/.homeassistant/sensor/pir_entrance_one"
payload: "OFF"
retain: "true"
# Automation motion sensor entrance
- alias: "Motion entrance light during night time"
trigger:
- platform: state
entity_id: binary_sensor.foyer_light_motion
from: 'off'
to: 'on'
condition:
- condition: sun
after: sunset
action:
service: script.motion_foyer_light
this is the rf_receive.py script (last part)
while True:
if rfdevice.rx_code_timestamp != timestamp:
timestamp = rfdevice.rx_code_timestamp
if str(rfdevice.rx_code) == '971897':
i = i+1
logging.info("Detect code " + str(rfdevice.rx_code) + " i=" + str(i))
if i == 10:
publish.single("/home/hass/.homeassistant/sensor/pir_entrance_one","ON",hostname="localhost", auth=auth)
i = 0
time.sleep(60)
time.sleep(0.01)
rfdevice.cleanup()
Hi you now why the code is correctly going from of to on, but then stays on??
Hi,
I made my RF433 PIR Motion/MQTT automation with appdaemon. A true/smart motion is considered If two (o more) signals arrive to mqtt topic between a X period of time. if a true motion is detected and the alarm state is “armed”, send me a notification (telegram).
The sensor:
- platform: mqtt
name: "PIR Comedor"
state_topic: "home/433toMQTT"
command_topic: "home/commands/MQTTto433/PLSL_307/433_1"
payload_on: "xxxxxxxx" #put your RF Code here
payload_off: "OFF_PIR_COMEDOR"
optimistic: false
retain: false
device_class: motion
The config of the script:
pir_motion_1:
alarm_control_panel: alarm_control_panel.alarma
class: MotionPir
command_topic: home/commands/MQTTto433/PLSL_307/433_1
delay: '8'
module: motion
payload_off: OFF_PIR_COMEDOR
sensor: binary_sensor.pir_comedor
This is the my appdaemon script (the logs are in spanish ):
import appdaemon.appapi as appapi
class MotionPir(appapi.AppDaemon):
def initialize(self):
self.handle = None
self.motion_counter = 0
self.sensor = self.args["sensor"]
self.command_topic = self.args["command_topic"]
self.payload_off = self.args["payload_off"]
self.alarm_control_panel = self.args["alarm_control_panel"]
self.listen_state(self.motion, self.sensor)
self.turn_off_motion_sensor()
def motion(self, entity, attribute, old, new, kwargs):
if new == "on":
self.motion_counter = self.motion_counter + 1
self.log("Movimiento detectado en sensor ({}).".format(self.motion_counter))
self.turn_off_motion_sensor()
if self.motion_counter > 1:
self.send_notification()
self.cancel_timer(self.handle)
self.handle = self.run_in(self.reset_motion_counter, self.args["delay"])
def turn_off_motion_sensor(self):
self.call_service("mqtt/publish", topic = self.command_topic,
payload = self.payload_off, qos = "0", retain = "false" )
def reset_motion_counter(self, kwargs):
self.log("Reiniciando contador de movimientos para sensor.")
self.motion_counter = 0
def send_notification(self):
if self.get_state(self.alarm_control_panel) == "armed_away":
self.log("Enviando notificación de movimiento detectado vía Telegram.")
self.call_service("notify/telegram", title = "Movimiento detectado", message = "[{}]".format(self.get_state(self.sensor, attribute="friendly_name")))
else:
self.log("Movimiento detectado, notificaciones desactivadas por alarma no activa.")