One click, more actions

Hello,

Newbie question here.
If i click (all single click) on a button i want three actions to happen with different entitiy’s.
How do i make that code efficient?
This is how i do it now:

- alias: Klik, weg of op bed
  trigger:
    platform: event
    event_type: click
    event_data:
      entity_id: binary_sensor.switch_158d00016bf4ca
      click_type: single
  action:
    service: light.turn_off
    data:
      entity_id: group.woonkamer

- alias: Klik, tv uit
  trigger:
    platform: event
    event_type: click
    event_data:
      entity_id: binary_sensor.switch_158d00016bf4ca
      click_type: single
  action:
    service: switch.turn_off
    data:
      entity_id: switch.yeelight_2

- alias: Klik, licht keuken en washok in avond aan
  trigger:
    -  platform: event
       event_type: click
       event_data:
         entity_id: binary_sensor.switch_158d00016bf4ca
         click_type: single
  condition:
     condition: time
     after: '21:30:00'
     before: '02:00:00'
  action:
    - service: light.turn_on
      data:
        entity_id: light.fibaro_system_fgd212_dimmer_2_level_4
        brightness: 50
    - service: light.turn_on
      entity_id: light.fibaro_system_fgd212_dimmer_2_level_2

Three times the same at code at alias.
Can i get the three actions together under the “click” code?
How do i do that?

Thanks!

This is what i tried, but thats not working…
What am i missing?

- alias: Klik, weg of op bed
  trigger:
    platform: event
    event_type: click
    event_data:
      entity_id: binary_sensor.switch_158d00016bf4ca
      click_type: single
  action:
    - service: light.turn_off
      data:
        entity_id: group.woonkamer
    - service: switch.turn_off
      data:
        entity_id: switch.yeelight_2
    - service: light.turn_on
      data:
        after: '21:00:00'
        before: '02:00:00'
        entity_id: light.fibaro_system_fgd212_dimmer_2_level_4
        brightness: 50
    - service: light.turn_on
      entity_id: light.fibaro_system_fgd212_dimmer_2_level_2

There is something wrong with the after and before, thats not working…
The last two entity’s have to turn on only between 21:00 to 02:00.

Thanks

- alias: Klik, weg of op bed
  trigger:
    platform: event
    event_type: click
    event_data:
      entity_id: binary_sensor.switch_158d00016bf4ca
      click_type: single
  action:
    - service: light.turn_off
       entity_id: group.woonkamer
    - service: switch.turn_off
      entity_id: switch.yeelight_2
    - service: light.turn_on
      entity_id: light.fibaro_system_fgd212_dimmer_2_level_2
    - condition: time
        after: '21:00:00'
        before: '02:00:00'
    - service: light.turn_on
      data:
        entity_id: light.fibaro_system_fgd212_dimmer_2_level_4
        brightness: 50
1 Like

Thanks, works like a charm!

Also got another question.

The last 2 services, the lights that turn on.
Both’s lights are connected to a motion sensor.
2 minutes no motion, turn off the light.

Is is possible that when the lights are turned on with this switch (only with this action) between 21:00 and 2:00 the dimmer gets disabled?
So that the light only has to go off when i turn them off with another switch.

Thanks!!

Sure, if by “connected to a motion sensor” you mean controlled by an automation. Just append this to the end of the list of actions:

  - service: automation.turn_off
    entity_id: automation.your_dimmer_automation

You will have to write another automation to turn it back on at 02:00:00.

Exactly where i was looking for!

Tnx :sunglasses: