How to turn trigger based PIR into components with events and hold timer

Hi all,
I have been playing around with Home Assistant and an RF433-to-MQTT gateway. This allows me to receive triggers from a 433Mhz PIR. The triggers are one offs and can be used in automation rules as a trigger.
I’d like to turn a simple light on, or an input_boolean to trigger other events, with this trigger and let it switch off after no trigger is received for a certain time. Creating an automation rule that switches on a light and switch it off after a set time I can but not sure how I can reset this timer so that it stays on longer and only switches off after no PIR motion has been detected for a while (e.g. 5 minutes).

How can I best automate this?

Regards,
Patrick

You can use a script…

Trigger it from the PIR

  timed_bedroom_lamp:
    alias: "Turn on bedroom lights and set timer"
    sequence:
      # Cancel old timers
      - service: script.turn_off
        data:
           entity_id: script.timer_bedroom_off
      - service: switch.turn_on
        data:
          entity_id:
            - switch.zw_pclamp_switch
            - switch.zw_bedroomsunlamp_bedroomsunlamp
            - switch.pibedroomceilingdimmer
      # Set new timer
      - service: script.turn_on
        data:
          entity_id: script.timer_bedroom_off

  timer_bedroom_off:
    alias: "Turn off bedroom lights"
    sequence:
        - delay:
            minutes: 45
        - service: homeassistant.turn_off
          data:
            entity_id: 
            - switch.zw_pclamp_switch
            - switch.zw_bedroomsunlamp_bedroomsunlamp
            - switch.pibedroomceilingdimmer

This from my script.yaml

1 Like

Hi Keith,
This works indeed. Usng scripts is new to me and I am also still learning to code automation and any other file.The speed to check configurations on a Pi2 and the error messages I got makes it challanging to quickly find errors and improve. E.g syntax errors. But you script helped me getting this bit done.
Thanks,
Patrick

1 Like

It is quite a big learning curve, pretty much vertical :wink:

Glad I could help :slight_smile:

I just use the state change on the PIR from on to off with a for timer of 45 minutes.

This seems to work without the complexity of the script.

I haven’t been able to validate this, but how would the timer be extended/reset in case motion is detected again prior to expiry of the timer?
I’d like to avoid the state to be changed to down based on the first event when a consequent one comes in before expiry.

It’s a trigger; so if the state goes ON to OFF but back ON before the “FOR” time is reached then it resets.

It specifically waits from ON to OFF to occur for 45 minutes (the FOR time).

Hi,

I tried but couldn’t get the “FOR” to work. Again, I still struggle with the yaml syntax but I don’t know how to further progress this or what exactly to expect. Here the piece I was working on in my automation.yaml file.

# PIR test to trigger timer.
- action:
  - alias: Switch on boolean
    service: homeassistant.turn_on
    entity_id: input_boolean.motion_detected_1
  trigger:
    platform: mqtt
    topic: "home/433toMQTT"
    payload: "14250874"
    for:
      minutes: 3
  alias: PIR trigger test basic
  initial_state: on
  hide_entity: true
  id: '1497893919247'

Ahhh! Sorry, for doesn’t work with a MQTT trigger. You will need to use MQTT to trigger; set a boolean, and then use the boolean as a state trigger with the for…

Hi Patrick,

Did you ever get this working with your MQTT setup? I am doing something very similar with MQTT PIR sensors, I would be very appreciative of seeing your working automation yaml code.

Hi Sparky,
I did get it working. But I still struggle with the sensitivity of Home Assistent. Too often my automations stop working or scripts don’t work which could be a result of a small error somewhere, which is mostly very hard to find with the very cryptic logging that is available. I am considering to stop using Home Assistant for now and consider again when it is mature enough, like with version 3.1 or so.
Patrick

1 Like