Automation trigger not working to turn light on

I’m trying to automate a yeelight lamp and I reach the conclusion that my automation does NOT trigger, even I have checked in the logs I can see the change happening ( is triggered by state)
I suspect this is a bug. I have a couple other automations, and they seem to be working
I have checked, and the Automation is actually enabled
I have spent hours trying to figure this out and I’m about to give up
Either there is a BUG in HA, or I am missing something very basic
here is my configuration:
configuration.yaml:
binary_sensor:

  • platform: mqtt
    name: “Spare switch”
    state_topic: “tele/sonoffrf/RESULT”
    value_template: ‘{{value_json.RfReceived.Data}}’
    payload_on: “36E358”
    payload_off: “36E358off”
    qos: 1
    off_delay: 1

and automations.yaml:

- id: '1553288065731'

alias: jon room turn on
trigger:

  • entity_id: binary_sensor.spare_switch
    for:
    seconds: 5
    from: ‘off’
    platform: state
    to: ‘on’
    condition: []
    action:
  • data:
    identity_id: light.jon_s_bedroom
    service: light.toggle
    initial_state: true

would appreciate if someboy can help me

Please try again following the instructions at the top of the page. Otherwise we cannot tell if you have indenting issues. Spaces are VERY important in yaml.

lets hope this time I do a better job:

# configuration.yaml:

binary_sensor:
- platform: mqtt
  name: "Spare switch"
  state_topic: "tele/sonoffrf/RESULT"
  value_template: '{{value_json.RfReceived.Data}}'
  payload_on: "36E358"
  payload_off: "36E358off"
  qos: 1
  off_delay: 1

#automations.yaml:

- id: '1553288065731'
  alias: jon room turn on
  trigger:
  - entity_id: binary_sensor.spare_switch
    for:
      seconds: 5
    from: 'off'
    platform: state
    to: 'on'
  condition: []
  action:
  - data:
      identity_id: light.jon_s_bedroom
    service: light.toggle
  initial_state: true

Thanks again

1 Like

you are using the wrong info in the “action:”

try this (assuming the light entity_id is correct):

action:
  - data:
      entity_id: light.jon_s_bedroom
    service: light.toggle

Well spotted!
I was playing with different actions and I messed with that entry
Anyway I corrected iit, but still doesn’t work.
When I click on the switch I can see the state changing on developers tools’ States for the binary sensor, but nothing happens!
Thanks anyway

I’m confused…

You don’t have any switches in the automation to trigger from. Only a binary_sensor.

Does the switch control the binary_sensor?

1 Like

sorry mate, I forgot to include the switch configuration
I’m at work right now, so don’t have it
suffice is to say, that when I click the sonoff rf switch, I can see - for a few seconds the “tick” on the sensor on HA Overview screen, also can see the status of the binary sensor changing from "off " to “on”, and then a few seconds later back to “off”
I will try to add that bit when I get to home tonight

Thanks again

if the binary sensor is only staying on for a couple of seconds then the automation won’t trigger since you have the "for: seconds: 5 " in the trigger. That means that the binary_sensor needs to stay on for a full 5 seconds before the automation will trigger. Try removing that section from the trigger and see if it works then.

Ok, I think I may have misled you
Just managed to check the configuration, and what I already sent you is all there is !
the binary sensor IS the switch
when I check in Developers Tools , States, there is an entity named binary_sensor.spare_switch
which I assume it is the mqtt “spare switch” of my configuration.yaml file
currently if I click my switch, that binary sensor changes state from off to on ( then a few seconds later back) , shouldn’t this change of state trigger the action? the time is on, shouldn’t matter

Maybe I’m talking nonsense!
What annoies me is that I can see the sensor flashing on HA, but can’t make a bloody light go on!

The other thing I realized is that the automation is the one that is doing the 5 sec change
Not sure I understand the logic behind, but I think it does turn off the binary sensor off, 5 secs after it has turned on
after doing that it should do the “action”, shouldn’t it?

which switch? you said there was no switch. just a binary sensor.

You can’t click on a binary sensor and change it’s state (because it’s just a “sensor”) unless you are forcing it with the “set state” button at the top. If you are doing it that way then it will only override the state of the binary sensor until the sensor updates itself from the system polling interval. If you are doing it that way then that’s why it’s going back off again right away.

As I explained above it’s not “the automation” that is setting the binary_sensor back to off. It’s the system polling setting the binary sensor to the “real” state based on the system information and removing the forced state that you put in.

and, then, since the binary sensor never actually gets switched to on for more than 5 seconds the automation never triggers. And I really can’t remember if forcing the state of that binary sensor to on will actually tell the system it’s on for automation purposes. Is there any way to actually turn the binary sensor on without forcing it? Where does the real state of the binary sensor come from? what device is it looking at for the state?

Success!!
I followed your advice and took the 5 secs off, this is how it looks now:
configuration.yaml

binary_sensor:
- platform: mqtt
  name: "Spare switch"
  state_topic: "tele/sonoffrf/RESULT"
  value_template: '{{value_json.RfReceived.Data}}'
  payload_on: "36E358"
  payload_off: "36E358off"
  qos: 1
  off_delay: 1

automations.yaml:

- id: '1553288065731'
  alias: jon room turn on
  trigger:
  - entity_id: binary_sensor.spare_switch
    platform: state
    to: 'on'
  condition: []
  action:
  - data:
      entity_id: light.jon_s_bedroom
    service: light.toggle
  initial_state: true

Thanks very much for your help - I though I was going crazy!

1 Like