Default choice trigger in automation

Hi,

I have a time trigger automation, firing every 30 seconds to activate a list of automations.

I notice that the correct automation gets fired based on its conditions. Below you see the YAML:

alias: Smartplugs (plugs + boiler)
description: Activeren van de smartplugs in functie van de zonne-energie
triggers:
  - id: 0W
    trigger: numeric_state
    entity_id:
      - sensor.solar_netto_produced
    below: 400
    for:
      seconds: 15
  - id: 450W
    trigger: numeric_state
    entity_id: sensor.solar_netto_produced
    above: 450
    below: 900
  - id: 900W
    trigger: numeric_state
    entity_id: sensor.solar_netto_produced
    above: 900
    below: 1200
  - id: 1200W
    trigger: numeric_state
    entity_id: sensor.solar_netto_produced
    above: 1200
    below: 1650
  - id: 1650W
    trigger: numeric_state
    entity_id: sensor.solar_netto_produced
    above: 1650
    below: 2100
  - id: 2100W
    trigger: numeric_state
    entity_id: sensor.solar_netto_produced
    above: 2100
    below: 2950
  - id: 2950W
    trigger: numeric_state
    entity_id: sensor.solar_netto_produced
    above: 2950
    below: 3400
  - id: 3400W
    trigger: numeric_state
    entity_id: sensor.solar_netto_produced
    above: 3400
    below: 3850
  - id: 3850W
    trigger: numeric_state
    entity_id: sensor.solar_netto_produced
    above: 3850
    below: 5300
  - id: 5300W
    trigger: numeric_state
    entity_id: sensor.solar_netto_produced
    above: 5300
conditions:
  - condition: numeric_state
    entity_id: input_number.boiler
    below: 95
  - condition: numeric_state
    entity_id: input_number.laadpaal_on
    below: 1
  - condition: numeric_state
    entity_id: input_number.boiler_on
    above: 0
  - condition: numeric_state
    entity_id: input_number.chauffage_on
    above: 0
actions:
  - choose:
      - conditions:
          - condition: template
            value_template: "{{ trigger.id == '0W' }}"
        sequence:
          - action: switch.turn_off
            target:
              entity_id:
                - switch.smartplug_89baf0_relay
                - switch.smartplug_cbcd0b_relay
                - switch.smartplug_ec6a00_relay
                - switch.smartplug_f28324_o1_relay
                - switch.smartplug_f283ff_o1_relay
                - switch.pd22300004302_charging
      - conditions:
          - condition: template
            value_template: "{{ trigger.id == '450W' }}"
        sequence:
          - action: switch.turn_off
            target:
              entity_id:
                - switch.smartplug_89baf0_relay
                - switch.smartplug_cbcd0b_relay
                - switch.smartplug_f28324_o1_relay
                - switch.smartplug_f283ff_o1_relay
                - switch.pd22300004302_charging
          - action: switch.turn_on
            target:
              entity_id:
                - switch.smartplug_ec6a00_relay
      - conditions:
          - condition: template
            value_template: "{{ trigger.id == '900W' }}"
        sequence:
          - action: switch.turn_off
            target:
              entity_id:
                - switch.smartplug_cbcd0b_relay
                - switch.smartplug_f28324_o1_relay
                - switch.smartplug_f283ff_o1_relay
                - switch.pd22300004302_charging
          - action: switch.turn_on
            target:
              entity_id:
                - switch.smartplug_ec6a00_relay
                - switch.smartplug_89baf0_relay
      - conditions:
          - condition: template
            value_template: "{{ trigger.id == '1200W' }}"
        sequence:
          - action: switch.turn_off
            target:
              entity_id:
                - switch.smartplug_ec6a00_relay
                - switch.smartplug_89baf0_relay
                - switch.smartplug_f28324_o1_relay
                - switch.smartplug_f283ff_o1_relay
                - switch.pd22300004302_charging
          - action: switch.turn_on
            target:
              entity_id:
                - switch.smartplug_cbcd0b_relay
      - conditions:
          - condition: template
            value_template: "{{ trigger.id == '1650W' }}"
        sequence:
          - action: switch.turn_off
            target:
              entity_id:
                - switch.smartplug_ec6a00_relay
                - switch.smartplug_f28324_o1_relay
                - switch.smartplug_f283ff_o1_relay
                - switch.pd22300004302_charging
          - action: switch.turn_on
            target:
              entity_id:
                - switch.smartplug_cbcd0b_relay
                - switch.smartplug_89baf0_relay
      - conditions:
          - condition: template
            value_template: "{{ trigger.id == '2100W' }}"
        sequence:
          - action: switch.turn_off
            target:
              entity_id:
                - switch.smartplug_f28324_o1_relay
                - switch.smartplug_f283ff_o1_relay
                - switch.pd22300004302_charging
          - action: switch.turn_on
            target:
              entity_id:
                - switch.smartplug_cbcd0b_relay
                - switch.smartplug_89baf0_relay
                - switch.smartplug_ec6a00_relay
      - conditions:
          - condition: template
            value_template: "{{ trigger.id == '2950W' }}"
        sequence:
          - action: switch.turn_off
            target:
              entity_id:
                - switch.smartplug_ec6a00_relay
                - switch.smartplug_f28324_o1_relay
                - switch.smartplug_89baf0_relay
                - switch.pd22300004302_charging
          - action: switch.turn_on
            target:
              entity_id:
                - switch.smartplug_cbcd0b_relay
                - switch.smartplug_f283ff_o1_relay
      - conditions:
          - condition: template
            value_template: "{{ trigger.id == '3400W' }}"
        sequence:
          - action: switch.turn_off
            target:
              entity_id:
                - switch.smartplug_ec6a00_relay
                - switch.smartplug_f28324_o1_relay
                - switch.pd22300004302_charging
          - action: switch.turn_on
            target:
              entity_id:
                - switch.smartplug_cbcd0b_relay
                - switch.smartplug_f283ff_o1_relay
                - switch.smartplug_89baf0_relay
      - conditions:
          - condition: template
            value_template: "{{ trigger.id == '3850W' }}"
        sequence:
          - action: switch.turn_off
            target:
              entity_id:
                - switch.smartplug_f28324_o1_relay
                - switch.pd22300004302_charging
          - action: switch.turn_on
            target:
              entity_id:
                - switch.smartplug_cbcd0b_relay
                - switch.smartplug_f283ff_o1_relay
                - switch.smartplug_89baf0_relay
                - switch.smartplug_ec6a00_relay
      - conditions:
          - condition: template
            value_template: "{{ trigger.id == '5300W' }}"
        sequence:
          - action: switch.turn_off
            target:
              entity_id:
                - switch.pd22300004302_charging
          - action: switch.turn_on
            target:
              entity_id:
                - switch.smartplug_cbcd0b_relay
                - switch.smartplug_f283ff_o1_relay
                - switch.smartplug_89baf0_relay
                - switch.smartplug_ec6a00_relay
                - switch.smartplug_f28324_o1_relay
    default: []
mode: single

At the moment of activation the sensor.solar_netto_produced has a value of 1000W. Nonetheless I see that it just follows the default path as if it doesn’t meet any template conditions (which it should because there are actions defined for this in trigger id ‘900W’

The strange thing is that when I wait some time, lets say 10 minutes it does work. This gives me the impression that the triggering of the automation through another (30 second time triggered) automation does not necessarily work and it just gets triggered by its own conditions when there is a trigger (for example in this code, when the power exceeds 900W and triggers the 900-1200W portion of the trigger.

My goal is to activate the automation every 30 seconds to re-execute it’s code:

alias: 30 second trigger
description: ""
triggers:
  - trigger: time_pattern
    seconds: /30
conditions:
  - type: is_power
    condition: device
    device_id: a091fb88a4e2f5e188dde60fbbb67936
    entity_id: 1d9a1b33c76e82d1a0ee1adec08cb2c6
    domain: sensor
    above: 0
actions:
  - action: automation.trigger
    metadata: {}
    target:
      entity_id:
        - automation.smartplugs_boiler
        - automation.smartplugs_no_boiler
        - automation.smartplugs_boiler_laadpaal
        - automation.smartplugs_laadpaal
        - automation.smartplugs_enkel_boiler
    data:
      skip_condition: false
mode: single

Could anyone comment on this and advice why it is just following the default path?

Thanks in advance for your help.

If you manually run an automation then none of the triggers have fired, so there is no trigger id to test for. You can see no trigger fired in the trace graph.

It is advised against manually triggering automations and bypassing triggers, partly because of this reason. Actions you want to run without automation triggering is what scripts are for. You’d best use numeric state conditions in the choose instead of tests for a trigger.

ps. there is a dedicated condition for testing trigger ids. no need to use a template for it.

2 Likes

Thanks Edwin for your help.
I will have to investigate how this works because I have no experience with scripts.

A script is simply the action part of the automation but as a separate concept. You can call scripts from automations, from buttons, from voice commands…

This is another thing to remember once you get triggers triggering. Looking at the direction you are headed just want you to be sure to take this into account: Automations #1: trigger only fires when it changes from not true to true