Issue with automation to turn of light

Hi, in my bathroom i recently installed a Ikea Gunnarp Led panel. I would like to have a automation which makes it possible when i press the Tradfri Remote, the light turns on with a certain level of brightness. There must be difference between the brightness during the evening and the night. If you go to the bathroom in the night i don’t want to be surprised with a full 100% brightness light :wink:
Since the tradfri light remembers the last used brightness level, i thougt that turning off the light in the evening with a transition was a good idea. When i turn on the light in the night, it will start with the lowest level of brightness which is fine for me.
I have created the following 2 automations, but when i both turn the automations on , i can turn on the light, but it won’t turn off anymore:

- id: Turn on bathroom light
  alias: Turn on bathroom light
  trigger:
    - platform: state
      entity_id: light.badkamer
      from: 'off'
      to: 'on'
  condition: 
  - condition: and
    conditions:
    - after: sunset
      condition: sun
    - before: '23:30'
      condition: time      
  action:
    - service: light.turn_on
      data:
        entity_id: light.badkamer
        brightness: 190
        color_temp: 370

And the second one, when i want to turn it off:

- id: Turn off bathroom light
  alias: Turn off bathroom light
  trigger:
    - platform: state
      entity_id: light.badkamer
      from: 'on'
      to: 'off'
  condition:
  - condition: and
    conditions:
    - after: sunset
      condition: sun
    - before: '23:30'
      condition: time
  action:
    - service: light.turn_off
      data:
        entity_id: light.badkamer
        transition: 2

Am i doing something wrong ? When i try to turn the light off , i see in the history of the specific light: “Turned on by service light.turn_off” which sounds a bit odd to me?

Hi, from my experience transition won’t work on ikea devices.
But that ofc can be me doing wrong :slight_smile:
I am using conbee1 and deconz.
But i can use transition on my Hue devices.

Perhaps helpful :slight_smile:

If i only use automation 2 it works. Not as nice as on a Hue light (from what i read) but there is definitely a transition going on, which makes it more comfortable to a sudden switch off

The second automation intrigues me. It triggers when someone turns off the light and then … turns it off again.

Why exactly do you have it doing that? Is the assumption that it will somehow remember to use transition: 2 when someone turns it on again later? Or is it for another reason?

No there is no specifc reason. I don’t know how to make a automation that starts the transition action as soon as the light is turned off by the Tradri Remote.
From what i understand, i have to have the Turn off light action in the automation, otherwise i don’t have any idea where to define the transition action ? The same counts for the first automation. Basically the light is already turned on by the Tradfri Remote, so a turn on action is not needed by the script… Any suggestions how to it better are welcome :slightly_smiling_face:

If you use a Tradfri Remote, you can create an automation that listens to the Remote’s button events and then decide which commands to send to the light. In other words, the Tradfri Remote does not control the light directly but only through the automation which acts as a ‘middleman’.

From what I understood is that the only status you can read from the Tradfri remote is the battery status ?

oh i totaly missed that you used the light as the trigger. my bad.
as 123 writes, you should integrate the remote aswell.
And then listen to the button pushed

    platform: event
    event_type: deconz_event
    event_data:
      id: hall_fjarr
      event: 1002

If you are using deCONZ, the documentation explains the event codes transmitted for each button action: Remote Control Devices

Example (change id: to match whatever represents your Remote and event: to the preferred button and action code):

- alias: Example 1
  trigger:
  - platform: event
    event_type: deconz_event
    event_data:
      id: tradfri_remote_control
      event: 1002
  action:
  - service: light.turn_on
    data:
      entity_id: light.badkamer
      brightness: 190
      color_temp: 370

I am not a deconz user… is there no other way?

ZHA

Ok but this basically means I have to have new/other hardware ? With the current software and the Tradfri remote controle it’s not possible ?

Which integration are you using that permits communication between Home Assistant and the Tradfri Remote Control and Gunnarp LED panel?

I have added the Tradfri Hub in to the home assistant system , and I am using Zigbee2mqtt, which has nothing to do with this automations since this is al controlled by the Tradfri Hub

I’d suggest removing any automation in the Tradfri Hub and doing it all via HA. Then you don’t have that issue. If both the light and remote are interfaced with HA this should be easy enough.

The Tradfri Hub is not doing any automation. I am only using the Hub to connect the lights and remotes to the HA system. From there I use HA for all my automations.

Is this the Remote Control you have?

Is it paired directly with the light or with the Tradfri hub? In other words, if the hub is powered off, can the Remote still control the light?

On the other hand, if the Remote is paired with the hub, zigbee2MQTT will publish payloads to topics representing the Remote. Home Assistant can receive payloads published to those topics.

Indeed, that’s the remote control I have. So what you suggest to do is remove the remote control from the Tradfri Hub (from the Hub it controls the light) and connect it to the Zigbee2mqtt stick?

Second script only works between sunset and 23:30. If you turn the light off later it will do nothing because of your condition after the trigger.
Propose to add another condition that will include the rest of the night until sunrise.

Correct. The goal is to permit ZigBee2MQTT to report the Remote Control’s button events to Home Assistant. The automation you create listens for the button events and proceeds to turn lights on/off as you desire.