Rpi_rf based automation works manually but not with time trigger

I’ve been scratching my head on this one for a few weeks…

This year I put my house’s Christmas lights on a RF outlet controlled by Home Assistant by way of the rpi-rf switch. I’m going to leave out the switch configuration, because it works perfectly – I can turn on and off the switch manually without issue (so I know the codes / frequency are correct, and the range of the transmission doesn’t seem excessive).

I use an automation with the sun trigger to turn on the lights at sunset. It works brilliantly, every time.

- alias: turn on christmas lights                                                                                                                                                                                               
    trigger:                                                                                                                                                                                                                      
      platform: sun                                                                                                                                                                                                               
      event: sunset                                                                                                                                                                                                               
      offset: '+00:00:00'                                                                                                                                                                                                         
    action:                                                                                                                                                                                                                       
      service: switch.turn_on                                                                                                                                                                                                     
      entity_id: switch.christmas_lights

However, my automation to turn the lights off at 8:30 pm, using the time platform doesn’t seem to ever work.

- alias: turn off christmas lights                                                                                                                                                                                              
    trigger:                                                                                                                                                                                                                      
      platform: time                                                                                                                                                                                                              
      after: '20:30:00'
    action:                                                                                                                                                                                                                       
      service: switch.turn_off                                                                                                                                                                                                    
      entity_id: switch.christmas_lights

Here’s the thing – I’m pretty sure it should work, because if I trigger it manually with the developer tools using automation.trigger with {"entity_id": "automation.turn_off_christmas_lights"}, it works brilliantly, and at 8:30 PM every night, I see in my logbook Turn Off Christmas Lights has been triggered – but the light doesn’t turn off.

I’ve worked with a few RF libraries on the Pi before and had issues getting reliable transmission when the CPU was busy (presumably because it’s not a RTOS), but if this were the cause I would expect unreliable transmission at other times as well (e.g. at sunset – but it reliably gets turned on, or when triggering manually – but it seems to work every time manually).

Any ideas?

  • The switch works
  • The automation works when manually triggered
  • The time trigger seems to be triggered appropriately
  • The switch just isn’t getting turned off

I have a USB charger that I turn off every night at 11pm. The only difference I’m seeing between our automations is the use of switch.turn_off vs homeassistant.turn_off.

It seems unlikely I would have done it this way unless switch.turn_off failed to work in an automation for me.

  alias: Bedroom Charger Off
    trigger:
      platform: time
      after: '23:00:00'
    action:
      service: homeassistant.turn_off
      entity_id: switch.zw_bedswitch_switch_7_0

I know switch.turn_off works, since I use it without issue:

trigger:
  platform: time
  after: '23:59:00'
action:
  service: switch.turn_off
  entity_id: switch.drive_5_0

Sadly, this doesn’t help with the source of the OP’s problem

Was never able to figure this out. Taking down Christmas lights for the year, so we’ll see if this pops up with other devices.

I have experienced similar behaviour using tasker with my limitlessLed lighting. It was something to do with the timing and I got around it by sending the UDP commands 3 times in a row with different delays between each sending. There was something in the documentation about delays between commands in the order of 100ths of a second that led me to try this. Interestingly I have never experienced this with Hass - although my pi is connected by ethernet unlike the phone.

It’s a long shot but perhaps the RF outlet behaves similarly?

Definitely could be – was wondering if this will help.

Then again, if this were the problem, makes no sense to me why it would reliably turn on, and reliably turn on and off manually.

Just an update, finally fiddling around with this a bit today –

I pulled out a switch, and manually turned it on, then set 3 different time-based automations to turn it off. All three automations were identical (copied and pasted), with the exception of adding an identifier to the end of the alias (e.g. - alias: Turn off switch one again), and incrementing the time by 15 seconds (e.g. after: '09:58:15') and incrementing the minute to the current time + 1.

- alias: Turn off switch one                                                                                                                                                                                                    
    trigger:                                                                                                                                                                                                                      
      platform: time                                                                                                                                                                                                              
      after: '09:58:00'                                                                                                                                                                                                           
    action:                                                                                                                                                                                                                       
      service: switch.turn_off                                                                                                                                                                                                    
      entity_id: switch.rf_switch_one

Interestingly, the first automation continued to not work, while consistently the second one (15 seconds past the minute) worked fine.

That made me wonder if perhaps things were just too busy at the top of the minute, so I changed the first automation to 1 second after the minute, e.g. '09:58:01'. Then it started working.

Then, I thought I’d try to reproduce the bug again by going back to :00 seconds… but the bug never came back. It seems to now be working at e.g. '09:58:00'… just as well as any other time.

Finally, to make sure I hadn’t accidentally changed some hidden character or removed some nbsp that was gumming things up, I undid all my changes to the file, and I still can’t reproduce – now working at HH:MM:00 whereas just a few minutes ago it was falling through to the HH:MM:15 every time.

Very weird. I don’t think it was a cached setting problem (don’t know if HA even does this), because I was updating the minute on the :00 automation, and it still wasn’t working. No idea what it may have been. Glad it’s working now.

I would like to turn on the standing light that is connected Rfi switch outlet when the sun sets but it’s not working via automation.

But same outlet works manually via remote and also via HASS.

automation:

  #Turn on light when sun sets - living_room_ikea_light friendly name 'Living room light'
  - alias: Turn on light when sun sets
    trigger:
      platform: sun
      event: sunset
      offset: "-01:00:00"
    action:
      entity_id: switch.living_room_ikea_light
      service: homeassistant.turn_on

From log:

17-03-13 11:41:12 homeassistant.core: Bus:Handling <Event call_service[L]: service_call_id=1978166672-8, service_data=entity_id=switch.living_room_ikea_light, service=turn_on, domain=homeassistant>
17-03-13 11:41:12 homeassistant.core: Bus:Handling <Event call_service[L]: service_call_id=1978166672-9, service_data=entity_id=[‘switch.living_room_ikea_light’], service=turn_on, domain=switch>
17-03-13 11:41:12 homeassistant.components.switch.rpi_rf: Sending code: xxxxx

17-03-13 11:41:12 homeassistant.core: Bus:Handling <Event state_changed[L]: new_state=<state switch.living_room_ikea_light=on; friendly_name=Living room light @ 2017-03-13T11:41:12.711033-05:00>, entity_id=switch.living_room_ikea_light, old_state=<state switch.living_room_ikea_light=off; friendly_name=Living room light @ 2017-03-12T20:08:15.331940-05:00>>
17-03-13 11:41:12 homeassistant.core: Bus:Handling <Event state_changed[L]: new_state=<state group.all_switches=on; order=0, auto=True, friendly_name=all switches, entity_id=(‘switch.living_room_ikea_light’, ‘switch.formal_living_room_light’, ‘switch.formal_dining_room_light’, ‘switch.bed_room_standing_fan’), hidden=True @ 2017-03-13T11:41:12.721336-05:00>, entity_id=group.all_switches, old_state=<state group.all_switches=off; order=0, auto=True, friendly_name=all switches, entity_id=(‘switch.living_room_ikea_light’, ‘switch.formal_living_room_light’, ‘switch.formal_dining_room_light’, ‘switch.bed_room_standing_fan’), hidden=True @ 2017-03-12T21:22:06.653843-05:00>>
17-03-13 11:41:12 homeassistant.core: Bus:Handling <Event state_changed[L]: new_state=<state group.switches_card=on; order=15, friendly_name=Switches, entity_id=(‘switch.formal_dining_room_light’, ‘switch.formal_living_room_light’, ‘switch.living_room_ikea_light’, ‘switch.bed_room_standing_fan’) @ 2017-03-13T11:41:12.729291-05:00>, entity_id=group.switches_card, old_state=<state group.switches_card=off; order=15, friendly_name=Switches, entity_id=(‘switch.formal_dining_room_light’, ‘switch.formal_living_room_light’, ‘switch.living_room_ikea_light’, ‘switch.bed_room_standing_fan’) @ 2017-03-12T21:22:06.658951-05:00>>