State change automation question

This automation is designed to turn on the light above my smoker, if it is fired up around sunset or is found to be running once time gets close to sunset. The second part is designed to turn off the light 10 minutes after it is switched off.

If I comment out the second set of conditons and the coresponding sequence the automation loads. To me the second set is almost a mirror of the first set. Commenting out the for: does not make it load either.

I really want the second set to follow a transition to the “off” state so as not to affect the light state if manually turned on.

This error results from reloading automations:

Invalid config for [automation]: [to] is an invalid option for [automation]. Check: automation->action->0->choose->1->conditions->0->to. (See ?, line ?). 

Automation:

- id: "Grill light control"
  alias: "Grill light control"
  trigger:
    - platform: time_pattern
      minutes: /3
  mode: single
  action:
    - choose:
        - conditions:
            - condition: state
              entity_id: climate.bull
              state: heat
            - condition: sun
              after: sunset
              after_offset: '-00:15:00'
          sequence:
            - service: light.turn_on
              entity_id: light.grill
        - conditions:
            - condition: state
              entity_id: climate.bull
              state: off
              for: '00:10:00'
          sequence:
            - service: light.turn_off
              entity_id: light.grill

If I set the second condition to “state: heat”, the automation loads. It will not take “state: off”. Developers Tools/States does show the valid states are off and heat.

on:

Off:

Thanks Matt

I found why the automation would not load. For some reason the following line needed to be changed form “state: off” to “state: ‘off’”

I added the input_boolean to guard against turning off a manually turn on light and have tested basic function and it seems to work now.

Updated automation:

- id: "Grill light control"
  alias: "Grill light control"
  trigger:
    - platform: time_pattern
      minutes: /3
    - platform: state
      entity_id: climate.bull
  mode: single
  action:
    - choose:
        - conditions:
            - condition: state
              entity_id: climate.bull
              state: heat
            - condition: sun
              after: sunset
              after_offset: '-00:15:00'
          sequence:
            - service: light.turn_on
              entity_id: light.grill
            - service: input_boolean.turn_on
              entity_id: input_boolean.grill_light
        - conditions:
            - condition: state
              entity_id: climate.bull
              state: 'off'
              for: '00:10:00'
            - condition: state
              entity_id: input_boolean.grill_light
              state: 'on'
          sequence:
            - service: light.turn_off
              entity_id: light.grill
            - service: input_boolean.turn_off
              entity_id: input_boolean.grill_light

The reason is because the word off without quotes is the name of a variable representing a binary value, namely the value known as false. Same goes for the word on which is binary value true. When wrapped in quotes, they are no longer interpreted as being variables but as strings.

On a separate note, why does your automation employ a Time Pattern Trigger? The conditions used in choose would make good triggers and so the automation would trigger only when truly required (as opposed to every three minutes whether necessary or not).

Thanks for the explanation, that makes sense now.

As for the time trigger… The light is being triggered by the state of the smoker and the state of the sun. This is a smoker and sometimes it may be on for 20+ hours and would see transitions for day to night and back to day. The light is led, very little power consumption. So, the time trigger makes sure that the light gets turned on around sunset, I forgot to add a turn off around sunrise. There are times during the deep night that one needs to tend to things on the smoker and in is much easier with a light on.

Is there a better approach to making that happen? My understanding is that the triggers are “and”'ed. So, I do not see a way to use climate.bull as a solo trigger. Are you saying that I could remove the time pattern and the conditions would turn the light on if required by the sun platform?

I figured that the automation would be dormant unless the entity climate.bull changed state and triggered a run through the automation. climate.bull is always in the state “heat” if the power is on.

I am up to learn a better way to make it happen, would help with other automations.

Thanks Matt

Does this summarize what you want:

  • Turn the light on at Sunset, but only if the smoker is running.

  • Turn the light off 10 minutes after the smoker has stopped.

  • Turn the light off at Sunrise if the smoker is running.

It appears to after I added the after sunrise condition. I will likely slow down the time pattern trigger, now that it appears to work.

If there is a better way, please feel free to suggest it.

Thanks