Template trigger for zwave not working

{% for zwave in states.zwave if zwave.attributes.battery_level%}
{%- if zwave.attributes.battery_level | int < 15 -%} {{true}}
{%- endif -%}{%- endfor -%}

the above works but only if the state is not zero? if it goes from say 20 to 0 then this will not trigger and it doesn’t show true in template dev panel.

Anyone see how I can fix this?

This should never trigger if it’s a template trigger. You don’t have a entity_id to spark the trigger.

link to trigger documentation:

blurb in the documentation that explicitely describes the issue you are running into:

You don’t have any recognized entities. An entity is comprised of a domain and an object_id together, i.e. the entity_id.

- id: id_113
alias: Zwave Low Battery Notification
trigger:
platform: template
value_template: "{% for zwave in states.zwave if zwave.attributes.battery_level
  %}  {%- if zwave.attributes.battery_level | int < 15 -%}    {{true}}
   {%- endif -%}{%- endfor -%}"
action:
- service: notify.webpush_matthews_s8_plus
data_template:
  message: '{{ trigger.to_state.attributes.friendly_name }} needs new batteries currently {{ 
trigger.to_state.attributes.battery_level }} %'
- service: persistent_notification.create
data_template:
  message: '{{ trigger.to_state.attributes.friendly_name }} needs new batteries currently {{  trigger.to_state.attributes.battery_level }} %'
  title: "Low Battery"

this does work though and I get a notification but only if its not zero?

I guess you found a bug. It shouldn’t work at all. What version of HA are you on?

latest 83.3

Are you sure it’s triggering? I could see this only triggering on restart and then never again.

Here’s how I solved similar by using a time trigger and moving the zwave loop into the condition. It’s been working well.

- alias: battery_notification
  initial_state: True

  trigger:
    - platform: state
      entity_id: input_number.battery_alert_threshold

    - platform: time
      minutes: '/60'
      seconds: 00
       
  condition:
    - condition: template
      value_template: >-
        {%- set battery_alert_threshold = states('input_number.battery_alert_threshold') | int -%}
        {{ states | selectattr('attributes.battery_level', 'defined') | selectattr('attributes.battery_level','<', battery_alert_threshold ) | list | length >= 1 }}
  
  action:
    - service: script.notify_all_engines
      data_template:
        title: "Low Battery levels"
        who: "john"
        message: >-
          {%- set battery_alert_threshold = states('input_number.battery_alert_threshold') | int -%}
          {%- set low_batteries = states | selectattr('attributes.battery_level', 'defined') | selectattr('attributes.battery_level','<', battery_alert_threshold ) | map(attribute='name') | list | join(', ') -%}
          Low batteries in the following devices: {{ low_batteries }}

it seems to be yes If I set the threshold higher then I do get notifications.

Are you pressing the button to make it fire? Because that doesn’t count as triggering automatically. That’s a manual trigger and it does not look at your trigger function.

no waiting for the value to change in the zwave attribute some of my battery powered devices seem to fluctuate between a few percent so it it set it above that and it drops I get notified. I just don’t understand if it drops to 0 then it doesn’t trigger?