Trigger Platfrom "state/condition" or "template" what is better?

Hi All,

I had this automation below: Its trigger on state of

sensor.hacs
- id: "16625564-ef5e-4743-9586-29b33667bcc0"
  alias: "Notification - HASC Update"
  mode: restart
  trigger:
    - platform: state
      entity_id: sensor.hacs

  condition:
    - condition: numeric_state
      entity_id: sensor.hacs
      above: 0

  action:
    - service: script.mobile_notify_no_actionable
      data:
        title: "HASC Updates"
        message: "{{ trigger.to_state.attributes.friendly_name }} have {{ trigger.to_state.state }} updates"
        thread_id: "system_notification"

I changed it to this way: Trigger on template.
Code is shorter:

- id: "16625564-ef5e-4743-9586-29b33667bcc0"
  alias: "Notification - HASC Update"
  mode: restart
  trigger:
    - platform: template
      value_template: "{{ (states('sensor.hacs') > '0') }}"

  action:
    - service: script.mobile_notify_no_actionable
      data:
        title: "HASC Updates"
        message: "{{ trigger.to_state.attributes.friendly_name }} have {{ trigger.to_state.state }} updates"
        thread_id: "system_notification"

Can someone tell me If this way is trigger same way, or are there some things that will be different.
Otherwise I will update some other automations also to template trigger.

Cheers,
Peter

The second automation will only trigger once, the first one will trigger on every change of the hacs sensor. You won’t notice any difference.

However for this specific automation, just use the numeric state trigger. Personally I find this more readable than your template trigger.

trigger:
  - platform: numeric_state
    entity_id: sensor.hacs
    above: 0

Also

trigger.to_state.attributes.friendly_name

can be simplified to

trigger.to_state.name

which will give the friendly name and default to the entity id if no friendly name has been specified.

1 Like