Lights automation mixed between sun elevation and time

Thanks for the info. I just find out that I have this automation on the Philips Hue app so yesterday it did overlap and it is not going to be a valid test.

I will try testing with the dev tools as you guided me later today, but I guess the next few days will tell.

Happy Holidays guys and thank you so much for the help.

1 Like

Hey @123 , I have another entity to add to the automation that goes on at the same time but off at 9 PM. How can I add it?

I did like this but the id: “off2” does seem to be a thing. It’s seems more to be a status id.

- id: "1671664177077"
  alias: "Lights: Exterior Automation"
  description: ""
  trigger:
    - platform: numeric_state
      entity_id: sun.sun
      attribute: elevation
      below: 1.8
    - platform: numeric_state
      entity_id: sun.sun
      attribute: elevation
      above: -3.1
    - platform: time
      id: "off"
      at: "00:00:00"
    - platform: time
      id: "off2"
      at: "21:00:00"
    - platform: homeassistant
      event: start
  condition: []
  action:
    - variables:
        e: "{{ state_attr('sun.sun', 'elevation') | float }}"
    - choose:
        - conditions:
            - condition: template
              value_template: "{{ e <= 1.8 }}"
            - condition: template
              value_template: "{{ is_state('light.exterior', 'off') }}"
            - condition: template
              value_template: "{{ is_state('light.exteriorspecial', 'off') }}"
            - condition: template
              value_template: "{{ is_state('switch.light_plug_1_switch', 'off') }}"
          sequence:
            - service: light.turn_on
              data: {}
              target:
                entity_id:
                  - light.exterior
                  - light.exteriorspecial
                  - switch.light_plug_1_switch
        - conditions:
            - condition: template
              value_template: "{{ e >= -3.1 }}"
            - condition: template
              value_template: "{{ is_state('light.exterior', 'on') }}"
          sequence:
            - service: light.turn_off
              target:
                entity_id: light.exterior
              data: {}
        - conditions:
            - condition: trigger
              id: "off"
          sequence:
            - service: light.turn_off
              data: {}
              target:
                entity_id:
                  - light.exteriorspecial
                  - switch.light_plug_1_switch
        - conditions:
            - condition: trigger
              id: "off2"
          sequence:
            - service: light.turn_off
              data: {}
              target:
                entity_id:
                  - light.on_off_plug_1_2
  mode: single

@123 So I applied your automation, that ended up my solution, end when I needed to add another identity I followed along with what it is.

Oh man, you are right, I pasted the wrong one into my automation. Let me fix it.

What about this? Does it look right?

- alias: 'Scheduled Exterior'
  trigger:
  - platform: numeric_state
    entity_id: sun.sun
    attribute: elevation
    below: 1.8
  - platform: numeric_state
    entity_id: sun.sun
    attribute: elevation
    above: -3.1
  - platform: time
    at: '00:00:00'
  - platform: homeassistant
    event: start
  action:
  - variables:
      e: "{{ state_attr('sun.sun', 'elevation') | float }}"
  - choose:
    - conditions:
      - "{{ e <= 1.8 }}"
      - "{{ is_state('light.exterior', 'off') or is_state('light.exteriorspecial', 'off') or is_state('switch.light_plug_1_switch', 'off')}}"
      sequence:
      - service: light.turn_on
        target:
          entity_id: 
            - light.exterior
            - light.exteriorspecial
            - switch.light_plug_1_switch
    - conditions:
      - "{{ e >= -3.1 }}"
      - "{{ is_state('light.exterior', 'on') }}"
      sequence:
      - service: light.turn_off
        target:
          entity_id: light.exterior
    - conditions:
      - "{{ 0 <= now().hour < 16 }}"
      - "{{ is_state('light.exteriorspecial', 'on') }}"
      sequence:
      - service: light.turn_off
        target:
          entity_id: light.exteriorspecial
    - conditions:
      - "{{ 0 <= now().hour < 13 }}"
      - "{{ is_state('switch.light_plug_1_switch', 'on') }}"
      sequence:
      - service: light.turn_off
        target:
          entity_id: switch.light_plug_1_switch
    default: []
  mode: single

Would you also explain this, I can’t understand how this matches 24:00 hour.

What about the additional entity I added?

I think I got it, but something is wrong with the last lines. I am getting this error Invalid config for [automation]: Expected a dictionary @ data['action'][1]['choose'][3]['conditions'][1]. Got None. (See /config/configuration.yaml, line 4) and when I remove the last piece it goes away. Any thoughts?

- alias: Scheduled Exterior
  trigger:
    - platform: numeric_state
      entity_id: sun.sun
      attribute: elevation
      below: 1.8
    - platform: numeric_state
      entity_id: sun.sun
      attribute: elevation
      above: -3.1
    - platform: time
      at: 00:00:00
    - platform: time
      at: "21:00:00"
    - platform: homeassistant
      event: start
  action:
    - variables:
        e: "{{ state_attr('sun.sun', 'elevation') | float }}"
    - choose:
        - conditions:
            - "{{ e <= 1.8 }}"
            - "{{ is_state('light.exterior', 'off') or is_state('light.exteriorspecial',
              'off') or is_state('light.on_off_plug_1_5', 'off')}}"
          sequence:
            - service: light.turn_on
              target:
                entity_id:
                  - light.exterior
                  - light.exteriorspecial
                  - light.on_off_plug_1_5
        - conditions:
            - "{{ e >= -3.1 }}"
            - "{{ is_state('light.exterior', 'on') }}"
          sequence:
            - service: light.turn_off
              target:
                entity_id: light.exterior
        - conditions:
            - "{{ 0 <= now().hour < 16 }}"
            - "{{ is_state('light.exteriorspecial', 'on') }}"
          sequence:
            - service: light.turn_off
              target:
                entity_id: light.exteriorspecial
        - conditions:
            - "{{ 21 <= now().hour < 16 }}"
            - "{{ is_state('light.on_off_plug_1_5', 'on')"
          sequence:
            - service: light.turn_off
              target:
                entity_id: light.on_off_plug_1_5
      default: []
  mode: single

Do you mean this one?

    - conditions:
      - "{{ 0 <= now().hour < 16 }}"
      - "{{ is_state('light.exteriorspecial', 'on') }}"
      sequence:
      - service: light.turn_off
        target:
          entity_id: light.exteriorspecial
    default: []
  mode: single

I believe is the one you posted to me, triggered at midnight to turn off these lights. Isn’t going to work?

Oh so you mean the last one. How would I achieve it then? I want to trigger the event at 21 to turn off that light and I couldn’t figure out the range I should specify there.

        - conditions:
            - "{{ 21 <= now().hour < 16 }}"
            - "{{ is_state('light.on_off_plug_1_5', 'on') }}"
          sequence:
            - service: light.turn_off
              target:
                entity_id: light.on_off_plug_1_5
- conditions:
            - "{{ now().hour >= 21 }}"
            - "{{ is_state('light.on_off_plug_1_5', 'on') }}"
          sequence:
            - service: light.turn_off
              target:
                entity_id: light.on_off_plug_1_5
1 Like