How to make the automation shorter?

I have two automation like this:

- alias: switch_toggle_lamp_gostinaia

  initial_state: true

  trigger:

  - platform: event

    event_type: xiaomi_aqara.cube_action

    event_data:

      entity_id: binary_sensor.cube_158dXXXXXXXXX

      action_type: shake_air

  condition:

    - condition: time

      after: '07:00:00'

      before: '00:00:00'

  action:

    - service: light.toggle

      data:

        entity_id: light.gostinaia

        brightness_pct: 100

        color_temp: 200

- alias: switch_toggle_lamp_gostinaia

  initial_state: true

  trigger:

  - platform: event

    event_type: xiaomi_aqara.cube_action

    event_data:

      entity_id: binary_sensor.cube_158dXXXXXXXX

      action_type: shake_air

  condition:

    - condition: time

      after: '00:00:00'

      before: '07:00:00'

  action:

    - service: light.toggle

      data:

        entity_id: light.gostinaia

        brightness_pct: 40

        color_name: blue

How can I make the automation shorter, check the time directly in the action section, and change the brightness and color of my lamp there. I am just starting to master HA and still do not know everything, I would be grateful if you would help me.

The following example is based on the choose feature which is described here: Choose a Group of Actions

- alias: switch_toggle_lamp_gostinaia
  trigger:
  - platform: event
    event_type: xiaomi_aqara.cube_action
    event_data:
      entity_id: binary_sensor.cube_158dXXXXXXXXX
      action_type: shake_air
  action:
  - choose:
    - conditions: "{{ 0 <= now().hour <= 7 }}"
      sequence:
      - service: light.toggle
        data:
          entity_id: light.gostinaia
          brightness_pct: 40
          color_name: blue
    default:
    - service: light.toggle
      data:
        entity_id: light.gostinaia
        brightness_pct: 100
        color_temp: 200
1 Like

thank you very much you helped me a lot

1 Like

You’re welcome!

Please consider marking my post (above) with the Solution tag. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic has an accepted solution. It helps users find answers to similar questions.