How do I detect whether my TRADFRI remote caused the state change of my lights as opposed to an automation?

Hi guys,

I am currently using a motion sensor to automatically turn my IKEA tradfri bulbs on in the bedroom. In addition to this, I am also using the custom component ‘circadian lighting’ to automatically sync the brightness of my lights to sun. But sometimes I want to overrule the circadian lighting and use my Tradfri remote to increase the brightness of my lights. However, the circadian lighting automatically kicks in and changes the brightness back to the circadian value.

What I am trying to do is detect whether my tradfri remote caused the state change of my lights as opposed to an automation. I can then use that information to temporarily disable the circadian lighting. Unfortunately I cannot get this to work using the trigger.xx attributes or looking at old_state and new_state using the state_changed events of my lights.

Basically I want to trigger on something that is similar to the newly added information to the logbook component that says ‘Bedroom lights have been turned on xxx’. This trigger should not fire when an automation is used to change the state of the lights.

Do any of your brilliant minds have an idea how to fix this?

Cheers,
Marvin

Wait for the next release, it’ll have a new integration called adaptive lighting, which should be able to do what you want without needing to detect your remotes changing the brightness. It’s based on the circadian lighring custom component, but completely rewritten.

There is a difference in ‘detecting the remote’ vs ‘detecting the light state change’.

Triggering on light state change means you will lose ALL information to why the state changed. At this point, something happened and told the light to do something. All you get is the light state before/after. So you’re going to have to manually capture the event BEFORE it turns on/off the lights and use THAT as your trigger.

First, you’ll have to set the disable entity/state in your circadian config.

disable_entity entity_id to use to disable this switch. entity_id None
disable_state State that disable entity must be in to disable this switch. String None

Just point to an input_boolean and set the state to be disabled when ‘on’.

Now you’re going to have to trigger on your remote events. I’m not sure how you have the remote integrated, but lets pretend its with the deCONZ integration. Whatever you use, it will be similar…trigger on some event that matches your remote button presses and turn on/off the input_boolean for some amount of time.

automation:
  - alias: 'Capture remote presses to light'
    # When the remote changes the light, turn off the circadian lighting component for 
    # x minutes. 
    # Change to mode restart, so every button press will restart this timer. 
    mode: restart
    trigger:
      # Capture ALL button presses here. Will pair down in condition
      - platform: event
        event_type: deconz_event
        event_data:
          id: remote_control_1
    condition:
      condition: template
      # Only care about certain button presses. Not all of them. Compare the first number of the event
      # to see if it's one of the following buttons. Don't really care if it was short or long press in this case. 
      value_template: "{{ trigger.event.data.event[0] in ["1", "2", "3", "4"] }}"
    action:
      - service: input_boolean.turn_on
        entity_id: input_boolean.circadian_disabled
      # Disable this for 20 minutes
      - delay: "00:20:00"
      - service: input_boolean.turn_off
        entity_id: input_boolean.circadian_disabled

Or use the adaptive lighting integration, which has this functionality built-in and which will also be the defacto replacement for the circadian custom component. Read the docs, it’s like circadian on steroids.

I agree with you there. I’m more answering the “how to tell if x turned on a light vs y”

1 Like

Thanks for the replies guys, but circadian lighting is just one of a few use cases where I need to tell if x turned on a light vs y. @jocnnor, I am using the IKEA bridge, so the remote control is not connected to HASS and is just controlling the bulbs, which means the remote control does not trigger an event except for the state_changed event of the light itself.

I basically just want the logbook functionality in my automations. Not sure how they do it, but in the logbook it mentions ‘Bedroom lights turned on’ (ikea remote) and ‘Bedroom lights turned on by automaiton.xxxx’ (automation).