Help with simple Automation: When an entity's attribute value is greater than its 'other' attribute value

All I want to do is trigger a notification when

sensor.threadfin_status [attribute:stream.all] > sensor.threadfin_status [attribute:stream.active]

Below, is my best attempt at doing this; even though I know it is wrong:

alias: Threadfin available IPTV channels available
description: ""
trigger:
  - platform: numeric_state
    entity_id: sensor.threadfin_status
    attribute: streams.all
    above: sensor.threadfin_status
    attribute: streams.active 
condition: []
action:
  - service: notify.sms_family
    data:
      message: >-
        Warning: New Threadfin IPTV channels available 
        Streams.active: {{ state_attr('sensor.threadfin_status', 'streams.active') }}
        Streams.all: {{ state_attr('sensor.threadfin_status', 'streams.all') }}
mode: single

A template trigger is more appropriate…

trigger:
  - platform: template
    value_template: |-
      {{ state_attr('sensor.threadfin_status','streams.all')|float(0) > state_attr('sensor.threadfin_status','streams.active')|float(0) }}

It’s unusual to have a . in the middle of attribute key, are you sure that you’re not dealing with sub-attributes? Post a screen grab of the entity information from the Developer Tools > States tool if you aren’t sure.

Note: The float() conversions may not be necessary, but without knowledge about the data type of your attributes, I decide to add them just in case.

Thank you. I’m not sure what to do with the code you gave me. I still need it to trigger the below action that’s in the automation I posted.

action:
  - service: notify.sms_family
    data:
      message: >-
        Warning: New Threadfin IPTV channels available 
        Streams.active: {{ state_attr('sensor.threadfin_status', 'streams.active') }}
        Streams.all: {{ state_attr('sensor.threadfin_status', 'streams.all') }}

The rest of your automation can stay the way it was, it was only the trigger that needed attention… From the screenshot, it looks like the attributes are already integers, so there is no need to convert them.

alias: Threadfin available IPTV channels available
description: ""
trigger:
  - platform: template
    value_template: |-
      {{ state_attr('sensor.threadfin_status', 'streams.all') > state_attr('sensor.threadfin_status', 'streams.active') }}
condition: []
action:
  - service: notify.sms_family
    data:
      message: >-
        Warning: New Threadfin IPTV channels available 
        Streams.active: {{ state_attr('sensor.threadfin_status', 'streams.active') }}
        Streams.all: {{ state_attr('sensor.threadfin_status', 'streams.all') }}
mode: single
1 Like

Thanks @Didgeridrew! I didn’t even know I could use templates as a trigger for automations. I now know what to do if I need to do something like this in the future.