RF 433 MHZ PIR motion sensor Raspberry PI configuration

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 :wink: ):

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.")