Smoker temperature probe notifications and if, else issue

First off, I stole the core of this code from this page:
https://community.home-assistant.io/t/any-way-to-consolidate-six-smoker-automations-into-fewer-ones/141350/4

I am trying to set up my smoker to notify myself, my wife or both of us. The problem is that if/elif/else does not seem to be the tool to use. My notifier is the first option, hers is the second and the else is a simple delay. If my notifier is on, I do get notified. If her notifier is on, she gets notified, if both notifiers are onā€¦ I only get notified.

I am using the Rec Tec integration to get data from my smoker.

Here is the logic:

- id: 'Probe setpoint notify'
  alias: Smoker Probe at temp
  trigger:
    - platform: template
      value_template: >
        {{ ( states('sensor.bull_probe_a_temperature')|float >= states('input_number.bull_probe_a_target')|float and
          not is_state('sensor.bull_probe_a_temperature' , 'unavailable') ) or ( states('sensor.bull_probe_b_temperature')|float
          >= states(' input_number.bull_probe_b_target')|float and not is_state('sensor.bull_probe_b_temperature' , 'unavailable') ) }}
  action:
    service_template: >
      {% if is_state('input_boolean.notify_grill_matt' , 'on') %} notify.sms_matt
      {% elif is_state('input_boolean.notify_grill_chris' , 'on') %} notify.sms_chris
      {% else %}
          delay: 00:00:00
      {% endif %}
    data_template:
      message: >
       {% if states('sensor.bull_probe_a_temperature')|float >= states('input_number.bull_probe_a_target')|float %}
         Attention! Probe A at set point of {{ states('sensor.bull_probe_a_temperature') }} F.
       {% else %}
         Attention! Probe B at set point of {{ states('sensor.bull_probe_b_temperature') }} F.
       {% endif %}

My other thought was to use the sensors from the integration mentioned above. The following could be used to notify based on the sensors below. I think it work will in a complex automation based on status change of the sensors below using the ā€œchooseā€ method in the automation.

sensor:
  - platform: template
    sensors:
      smoker_probe_a_status:
        value_template: >
          {% if states('climate.smoker') == 'off' or states('sensor.smoker_probe_a_temperature') == 'unavailable' -%}
            undefined
          {% else %}
            {% set target = states('input_number.smoker_probe_a_target')|round %}
            {% set actual = states('sensor.smoker_probe_a_temperature')|round %}
            {% set offset = actual - target %}
            {% if offset > 5 %}Over Temp!
            {% elif offset > -5 %}At Target
            {% elif offset > -15 %}Approaching...
            {% else %}Waiting...{% endif %}
          {%- endif %}

So, is the if/elif/else falling through as expected? If so, how would I modify it to work as I want it to?

Thanks Matt

Thatā€™s because if and elif are mutually exclusive. This line prevents the next elif from being evaluated when true , due to elif that will never be evaluated when the first is true

 {% if is_state('input_boolean.notify_grill_matt' , 'on') %} notify.sms_matt

You will need to test for every condition in a non-branch fashion , i.e.

if (condition1) {template}
if (condition2) {template}
...

I would also put the sensors in a group and trigger on group change to notify users according to which sensor changed, but thereā€™s many ways to cook this egg.

Thanks for the replyā€¦
I have also been working on this as an optionā€¦

- id: "Grill notify"
  alias: "Grill Notify"
  trigger:
    - platform: state
      entity_id: sensor.bull_probe_a_status
    - platform: state
      entity_id: sensor.bull_probe_b_status
  mode: restart
  action:
    - choose:
        - conditions:
            - condition: template
              value_template: "{{ trigger.to_state.state == 'At Target' }}"
          sequence:
            - service: notify.sms_matt
              data:
                title: "Meat approaching done"
                message: "One of the probes at set point."
            - service: notify.sms_chris
              data:
                title: "Meat approaching done"
                message: "One of the probes at set point."
        - conditions:
            - condition: template
              value_template: "{{ trigger.to_state.state == 'Approaching...' }}"
          sequence:
            - service: notify.sms_matt
              data:
                title: "Meat approaching done"
                message: "One of the probes approaching set point."
            - service: notify.sms_chris
              data:
                title: "Meat approaching done"
                message: "One of the probes approaching set point."
        - conditions:
            - condition: template
              value_template: "{{ trigger.to_state.state == 'Waiting...' }}"
          sequence:
            - service: notify.sms_matt
              data:
                title: "Meat approaching done"
                message: "One of the probes is responding but still cold."
            - service: notify.sms_chris
              data:
                title: "Meat approaching done"
                message: "One of the probes is responding but still cold."

I still have not been able to figure out how to notify only one person. I have input_booleanā€™s set up for each of us.

I am working to test your idea aboveā€¦ so I would end up with if/if/else? Testing now.

chose behaves just as an ā€˜ifā€¦elifā€¦elseā€™. The first conditions is the if, the next conditions are the elif and any default is the else

Also your mode restart means any previous trigger response is cancelled. Is that what you want, i.e. do you want bull_probe_a_status response to cancel bull_probe_b_status response if it is still excuting, and vice versa? Are you sure you do not want mode to be queued or even parallel ?

I have tried testing for bothā€¦ but I does not load. I am not very good at templates, sorry.

  action:
    service_template: >
      {% if is_state('input_boolean.notify_grill_matt' , 'on') %} notify.sms_matt
      {% if is_state('input_boolean.notify_grill_chris' , 'on') %} notify.sms_chris
      {% else %}
          delay: 00:00:00
      {% endif %}

May be the wrong mode selection. I assumed that if either changed state, the restart would fire the automation again and would text the new status. I think restart is what I am after as a text is sent with each change of either probe?

You canā€™t put the delay in the template like that, and even if you could it doesnā€™t do anything.

  action:
    service: >
      {% if is_state('input_boolean.notify_grill_matt' , 'on') %} notify.sms_matt
      {% else %} notify.sms_chris {% endif %}

I am not sure what you are trying to achieve because you are posting snippets of code that do not seem to be related and/or you keep changing them. Post the full config and explain what you want to happen - using pseudo code or something , and you cant ā€˜delayā€™ - and what would be the point of a zero delay anyway?

The delay is working as a place holder for the final stepā€¦ it is working.

The problem is that I need to test for one, or the other or both.

No, it isnā€™t, because itā€™s invalid syntax.

:roll_eyes: :roll_eyes: :roll_eyes: thatā€™s my queue , Iā€™m out

1 Like

What am I trying to do?
I have a smoker with 2 meat probes, 2 users and would like notifications to one, or the other or both based on input_boolean selections. I would really like to notify someone when one probe or the other is approaching a set point or when one or the other is at the setpoint. I would also like to notify someone when one probe or the other is at the desired temperature. The method of notification I am using is sms.

I am doing this because I do not like the lack of flexibility of the stock android app notifications. A smoke could be done in the middle of the night while asleep and 3 little beeps will not wake me up, but one or more sms messages will as my sms tone is selected to work best with my hearing deficiency.

I am playing with 2 different versions of automation The first one seems to be less elegant, but that could be that I do not understand how to make it more elegant. It only notifies when the target is reached or exceeded and if the first notifier is enabled it skips the second, And I have not figured out the third option of checking the input_boolean for the third option where both are notified.

- id: 'Probe setpoint notify'
  alias: Smoker Probe at temp
  trigger:
    - platform: template
      value_template: >
        {{ ( states('sensor.bull_probe_a_temperature')|float >= states('input_number.bull_probe_a_target')|float and
          not is_state('sensor.bull_probe_a_temperature' , 'unavailable') ) or ( states('sensor.bull_probe_b_temperature')|float
          >= states(' input_number.bull_probe_b_target')|float and not is_state('sensor.bull_probe_b_temperature' , 'unavailable') ) }}
  action:
    service_template: >
      {% if is_state('input_boolean.notify_grill_matt' , 'on') %} notify.sms_matt
      {% elif is_state('input_boolean.notify_grill_chris' , 'on') %} notify.sms_chris
      {% else %}
          delay: 00:00:00
      {% endif %}
    data_template:
      message: >
       {% if states('sensor.bull_probe_a_temperature')|float >= states('input_number.bull_probe_a_target')|float %}
         Attention! Probe A at set point of {{ states('sensor.bull_probe_a_temperature') }} F.
       {% else %}
         Attention! Probe B at set point of {{ states('sensor.bull_probe_b_temperature') }} F.
       {% endif %}

The other option I have been testing is as follows: This option just notifies us both based on the probe sensor settings assigned state based on the temperature of the probe. I have not figured out how to use the input_boolean to choose one of us or both of us. This one is the most verbose and relays states most accurately. I am triggering this based on the status change of either temperature probe.

- id: "Grill notify"
  alias: "Grill Notify"
  trigger:
    - platform: state
      entity_id: sensor.bull_probe_a_status
    - platform: state
      entity_id: sensor.bull_probe_b_status
  mode: restart
  action:
    - choose:
        - conditions:
            - condition: template
              value_template: "{{ trigger.to_state.state == 'At Target' }}"
          sequence:
            - service: notify.sms_matt
              data:
                title: "Meat approaching done"
                message: "One of the probes at set point."
            - service: notify.sms_chris
              data:
                title: "Meat approaching done"
                message: "One of the probes at set point."
        - conditions:
            - condition: template
              value_template: "{{ trigger.to_state.state == 'Approaching...' }}"
          sequence:
            - service: notify.sms_matt
              data:
                title: "Meat approaching done"
                message: "One of the probes approaching set point."
            - service: notify.sms_chris
              data:
                title: "Meat approaching done"
                message: "One of the probes approaching set point."
        - conditions:
            - condition: template
              value_template: "{{ trigger.to_state.state == 'Waiting...' }}"
          sequence:
            - service: notify.sms_matt
              data:
                title: "Meat approaching done"
                message: "One of the probes is responding but still cold."
            - service: notify.sms_chris
              data:
                title: "Meat approaching done"
                message: "One of the probes is responding but still cold."

Honestly, I am not sure what the best approach to take with this problem would be. I hope this makes more sense.

Matt

Ok, so the delay can and will go. It is not generating an errorā€¦ maybe it is not being used because the conditions never get there?

- id: 'Probe setpoint notify'
  alias: Smoker Probe at temp
  trigger:
    - platform: template
      value_template: >
        {{ ( states('sensor.bull_probe_a_temperature')|float >= states('input_number.bull_probe_a_target')|float and
          not is_state('sensor.bull_probe_a_temperature' , 'unavailable') ) or ( states('sensor.bull_probe_b_temperature')|float
          >= states(' input_number.bull_probe_b_target')|float and not is_state('sensor.bull_probe_b_temperature' , 'unavailable') ) }}
  action:
    choose:
      - conditions: 
          - {{ is_state('input_boolean.notify_grill_matt' , 'on') and is_state('input_boolean.notify_grill_chris' , 'on') }}
        sequence:
          - service: notify.sms_chris
            data:
              message: >
                {% if states('sensor.bull_probe_a_temperature')|float >= states('input_number.bull_probe_a_target')|float %}
                  Attention! Probe A at set point of {{ states('sensor.bull_probe_a_temperature') }} F.
                {% else %}
                  Attention! Probe B at set point of {{ states('sensor.bull_probe_b_temperature') }} F.
                {% endif %}
          - service: notify.sms_matt
            data:
              message: >
                {% if states('sensor.bull_probe_a_temperature')|float >= states('input_number.bull_probe_a_target')|float %}
                  Attention! Probe A at set point of {{ states('sensor.bull_probe_a_temperature') }} F.
                {% else %}
                  Attention! Probe B at set point of {{ states('sensor.bull_probe_b_temperature') }} F.
                {% endif %}
      - conditions: 
          - {{ is_state('input_boolean.notify_grill_chris' , 'on') }}
        sequence:
          - service: notify.sms_chris
            data:
              message: >
                {% if states('sensor.bull_probe_a_temperature')|float >= states('input_number.bull_probe_a_target')|float %}
                  Attention! Probe A at set point of {{ states('sensor.bull_probe_a_temperature') }} F.
                {% else %}
                  Attention! Probe B at set point of {{ states('sensor.bull_probe_b_temperature') }} F.
                {% endif %}
      - conditions: 
          - {{ is_state('input_boolean.notify_grill_matt' , 'on') }}
        sequence:
          - service: notify.sms_matt
            data:
              message: >
                {% if states('sensor.bull_probe_a_temperature')|float >= states('input_number.bull_probe_a_target')|float %}
                  Attention! Probe A at set point of {{ states('sensor.bull_probe_a_temperature') }} F.
                {% else %}
                  Attention! Probe B at set point of {{ states('sensor.bull_probe_b_temperature') }} F.
                {% endif %}

Itā€™s a little bit messier than the original but I think it should workā€¦as long as I have the indentation correct. I think I do.

It would be a little bit cleaner if you creatred a notify group out of your two notifiers annd then in the first conditions section you wouyld need the second service call since you could just send the message to the notifier group at the samer time iknstead of to both sequentially.

And I never checked you trigger template so I assume that is correct.