Allergy Notification

Have what I thought would be a simple notification of the allergy reading from the IQVIA integration.

Basically,
if level above 4 send a msg
else if level below 4 send a msg.

Here is the code:

alias: Allergy Forecast For Tomorrow
description: ""
trigger:
  - platform: numeric_state
    entity_id:
      - automation.allergy_forecast_for_tomorrow
    above: 4
    id: Greater_Than_4
  - platform: numeric_state
    entity_id:
      - automation.allergy_forecast_for_tomorrow
    below: 4
    id: Less_Than_4
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - Greater_Than_4
        sequence:
          - service: notify.mobile_app_phone
            metadata: {}
            data:
              message: Allergy Forecast Greater Than 4
      - conditions:
          - condition: trigger
            id:
              - Less_Than_4
        sequence:
          - service: notify.mobile_app_phone
            metadata: {}
            data:
              message: Allergy Forecast Greater Less Than 4
mode: single

However, when I test run the code, if skips the condition and ends.
And it is not triggered by IQVIA…and the allergy values do change day to day.

Appreciate inadance any help in understanding what is going wrong.

triggers only fire when one of the triggers changes from not true to true. see this:

so if the allergy forecast is above 4, stays above 4, then it the automation won’t trigger.

you said:

However, when I test run the code, if skips the condition and ends.

do you mean when you hit ‘run’ for the automation? if so, when you force run an automation, it skips all the triggers and runs only the actions. this means trigger.id doesn’t get set.

see this:
select the Run button. This will execute all of the actions , while skipping all triggers and conditions

what i think you want instead is for your trigger to be daily(?) … ie, “when” do you want something sent? i don’t think you want something sent on your current triggers. the “when” is daily or something like that, right?

also i’m not sure what entity (should be a sensor?) has the forecast, but it’s certainly not atuomation.allergy_forecast_for_tomorrow. that is this automation itself…

also you have “greater than 4” and “less than 4”
what if it’s 4?

this is not 100% right because i don’t know what entities you are trying to read and all, but this framework is right to solve the problems i’ve identified for you above:

alias: Allergy Forecast For Tomorrow
trigger:
  - platform: time_pattern
    hours: "8"
condition: []
action:
  - service: notify.mobile_app_phone
    data:
      message: >
        {% if states('sensor.whatever_sensor_really_has_the_forecast_for_tomorrow) > 4 %}
              Allergy Forecast Greater Than 4
        {% else %}
              Allergy Forecast less than or equal to  4
        {% endif %}

@armedad ok…let me take this observation/response in pieces…

First - I completely and I mean completely missed the “atuomation.allergy_forecast_for_tomorrow” aspect. Wow. Should have been: “sensor.allergy_index_tomorrow”.

continuing to read…pls stand by.

@armedad ok - reading and working to absorb the information you provided: Troubleshooting automations - Home Assistant. Yes - I did mean the run action. Thanks!

Further reading - on about testing conditions - thanks.

More reading on the “trigger only fires when it…”

When to trigger - daily - yes, as I understand the pollen count comes out once day.

What if it is “4”…yup - I was working on that concept. I like the concept you provided…seems simple and straight forwrd…in hindsight.

So, how do you set for the trigger to happen at 0100 (1 AM)? Set the time pattern to 0100 or “1” ? But “1” could be am or pm.

I did not know you could put logic into the message area. Nice.

Think I just learned…“0100” not correct. Time is based on a “24” hour clock 1 is am, vice 13 is 1pm.

@armedad Ok have copied your code and updated it with the correct sensor:

alias: 1-Allergy Forecast For Tomorrow
description: ""
trigger:
  - platform: time_pattern
    hours: "2"
condition: []
action:
  - service: notify.mobile_app_phone
    data:
      message: |
        {% if states('sensor.allergy_index_tomorrow') > 4 %}
              Allergy Forecast Greater Than 4
        {% else %}
              Allergy Forecast less than or equal to  4
        {% endif %}

but when testing - I get the following error:

Error: Error rendering data template: TypeError: '>' not supported between instances of 'str' and 'int'

so does not like the “>” symbol. So replaced it with “greater than” but received a malformed msg

Message malformed: template value should be a string for dictionary value @ data['action'][0]['data']

Newbie - that msg is a bit cryptic. But it does not like “greater than” wording (of course without the quotes).

oh, i think the sensor is coming in as a string. so my error is that it is comparing a string to a number. need to cast the string to a number… float right? i’m not familiar with what the sensor returns. if so, do the below. sorry about that.

alias: 1-Allergy Forecast For Tomorrow
description: ""
trigger:
  - platform: time_pattern
    hours: "2"
condition: []
action:
  - service: notify.mobile_app_phone
    data:
      message: |
        {% if states('sensor.allergy_index_tomorrow') | float > 4 %}
              Allergy Forecast Greater Than 4
        {% else %}
              Allergy Forecast less than or equal to  4
        {% endif %}

and yes, on the time. what you have sets it to send at 2am. i should have said above that i had set it to 8am… that would have clued you in more quickly on how to change it to whatever you want.

@armedad YUP! That was the fix. Let me test overnight…the test run worked…just need a live test.

I’ve gotta find a book, manual, course, etc on YAML.

that specifically was jinja, not yaml. home assistant uses jinja for templating

your mistakes weren’t yaml. They were home assistant specific or jinja

jinja…ok…something more to learn…very cool!

@armedad That worked ! Many thanks !