Strange Automation behavour RF Switches and Motion Sensors

Hi I’m new to Home Assistant, there for might miss something. I have switches, motion sensors, which works on fixed RF codes so I’m controlling lights (switches) using this type of config and that works flowless:

  - platform: rpi_rf
    gpio: 17
    switches:
      Toilet_Light01:
        code_on: 1020017
        code_off: 1020018
        signal_repetitions: 5

Now to get (RF) motion sensors to work (detected) I only found this combination, which is kind a working, using rflink integration and another device (arduino MEGA + transeiver with rflink firmware):

  - platform: rflink
    devices:              
      ev1527_0df4ce_00:
        name: Sensor Motion GarageOff
        device_class: motion
        off_delay: 5
      ev1527_0df4ce_0c:
        name: Sensor Motion GarageOn
        device_class: motion
        off_delay: 5        

Now I want to use automations and after searching and using official documentation I came up with this simple one for test purpose:

- alias: Turn on stairs light 2nd floor
  trigger:
    platform: state
    entity_id: binary_sensor.sensor_motion_garageon
    to: "on"
  action:
    service: switch.turn_on
    data:
      entity_id:
        - switch.2nd_floor_stairs_light01
        - switch.2nd_floor_stairs_light02

This automation is working, but HASSIO not sending actual RF codes. Switches shows that they switch in WEB interface, but nothing happens. But if I switch them manually they functions properly, WHY? What I’m missing?

Please try this

- alias: Turn on stairs light 2nd floor
  trigger:
    platform: state
    entity_id: binary_sensor.sensor_motion_garageon
    to: 'on'
  action:
  - service: switch.turn_on
    data: {}
    entity_id: 'switch.2nd_floor_stairs_light01, switch.2nd_floor_stairs_light02'

Thank you for prompt reply! That worked one time and again nothing (( ve aleikuma Salam.
Strange after HA restart it is working 1 time and no more? HA shows change of the state, but actual RF code not being generated again, very strange…After manual trigger it works one time, but after that no more…

1 Like

that is because when the first automation is triggered, the the switch is turned on and it continues to be in on state when you try the automation next time , the switch is still on, you have to turn the switch off again and turn on. try like that

Thanks checking…

- alias: Turn on stairs light 2nd floor
  trigger:
  - platform: state
    attribute: mode
    to: 'on'
    entity_id: binary_sensor.sensor_motion_garageon
  condition: []
  action:
  - service: switch.turn_on
    data: {}
    entity_id: switch.my_lab_light
  mode: single
  id: e2f172d7853d47b1a527d4c51060674b
- alias: Turn off stairs light 2nd floor
  trigger:
    platform: state
    entity_id: binary_sensor.sensor_motion_garageon
    to: 'on'
    for:
      seconds: 5
  action:
  - service: switch.turn_off
    data: {}
    entity_id:
    - switch.my_lab_light
  id: 810edd7077cb46bea31edd7ede87ff83

When I generated automation through UI, HA automaticaly assigned id’s to all other automations…)) and those can be edited through UI now…

Yes…that is correct. When we build automations from UI, HA assigns IDs to it . And we can only edit those automations which have such an id. If we remove the id , we have to edit if from automations.yaml. Did you check the automation problem?

Same same, UI shows that automation works fine, switch state changes, switch physically changes state, I see it in developer tools, but RF signal is not transmitted. Only if I manually toggle switch from UI it works, not through automation… why?

Its strange. This must be how you have tested. First execute the automation and since it is the first try, the switch should work. Then you have to go to UI and turn off the switch. Then try the automation again.

Even more strange is when I hit EXECUTE in automation panel it does what suppose to do, but not when it does it automatic.

that means the trigger we set is not working. Can you check if binary_sensor.sensor_motion_garageon is working and giving the state on and off?

Yes it does, everything works in UI, switches change their states, motion sensor changes state and shows that detected either clear, but RF signal is not transmitted…very strange Only if I hit switch in HA UI it transmits RF signal and switches light on and off…

Also another strange behavour is when I delete entries from UI which are removed from automation.yaml thay appear again after restart…

Rebooting HOST now.

Nothing, not working, just like before. This is HA bug!

I think the problem might be in signal interference How to make 1sek delay in switch after reception of command from motion sensor?

This cant be a bug, we are just missing something. So the automation works perfectly when you hit execute button in automation editor. But it is not triggering in automatic mode. This means the trigger is not working.

I think the problem could be with the binary sensor. Can you see the state of it changing to on when there is some motion?

Yes state is changing otherwise it woun’t trigger event, I have checked it it is changing in developer tools.

What I’m thinking maybe that is signal interference as motion sensor works on the same frequencies. How I can delay event trigger, say for 1-2 seconds?

This will delay action by 2 seconds.

- alias: Turn on stairs light 2nd floor
  trigger:
    platform: state
    entity_id: binary_sensor.sensor_motion_garageon
    to: 'on'
  action:
  - delay: '00:00:02'
  - service: switch.turn_on
    data: {}
    entity_id: 'switch.2nd_floor_stairs_light01, switch.2nd_floor_stairs_light02'
1 Like

Thanks, checking this. I have assembled separate RF receiver to see if signal is transmitted by HA. I can see motion sensor sending signal, but can’t see it from HA transmitter, just sometime it sends off signal

full code:

- id: '1611304514042'
  alias: New Automation Light ON
  description: ''
  trigger:
  - platform: state
    entity_id: binary_sensor.sensor_motion_garageon
    to: 'on'
  condition: []
  action:
  - delay: '00:00:02'
  - service: switch.turn_on
    data: {}
    entity_id: switch.my_lab_light
  mode: single
- id: '1611304642082'
  alias: New Automation Light OFF
  description: ''
  trigger:
  - platform: state
    entity_id: binary_sensor.sensor_motion_garageon
    to: 'off'
    for: 00:00:05
  condition: []
  action:
  - delay: '00:00:02'
  - service: switch.turn_off
    data: {}
    entity_id: switch.my_lab_light
  mode: single

OK signal repetition is not working in - platform: rpi_rf

signal_repetitions: 

I can see only 1 signal transmitted. I think that might be a problem:

 - platform: rpi_rf
    gpio: 17
    switches:
      LAB_Light01:
        code_on: 1020001
        code_off: 1020002
        signal_repetitions: 5

But since the UI switch works, it could not be an issue with signal repetition. It might not be getting picked up by the receiver.

Well not sure the problem might also be with signal repetition and delay. Because signal is transmitted only 1 time (I see it in serial monitor) I think it is getting lost between motion sensor signals (interference) After implementing delay automation works better but time to time, still the problem might be with automation.
Do you know how I can implement signal repetition?

TO diagnose this first we can try increasing the delay to 5 or 10s and see if the signal goes through.
And for repeating the signal we can try repeating the action to switch on the light again once or twice in the automation. It would literarily mean that the signal would be send again but dont know if the service will repeat with the switch turned on again.

1 Like