Help with detecting state change for automation

I have looked in the developer tools to see the state names and they are Idle and Heating Cycle.

I created an automation like this:

alias: Boiler needs stirring
description: When it is firing, but O2 is > 5% the coal bed isn't right
trigger:
  - platform: state
    entity_id:
      - sensor.heatmaster_boiler_status
    from: Idle
    to: Heating Cycle
    for:
      hours: 0
      minutes: 5
      seconds: 0
condition:
  - condition: numeric_state
    entity_id: sensor.heatmaster_o2
    above: 7
action:
  - service: notify.david_text
    data:
      message: Boiler needs stirred
mode: single

I want to receive a text message after the boiler has moved from Idle to Heating Cycle, wait for 5 minutes for the fire to get started, then check the O2 reading. If it is above 7%, then text me. That means it is not running correctly and I need to take action.

When I do this I can see that the state changes, but I never get a message even when the O2 level was 10%

I then simplified it to just text me when changing from Heating Cycle to Idle:

alias: Test state change
description: ""
trigger:
  - platform: state
    entity_id:
      - sensor.heatmaster_boiler_status
    from: Heating Cycle
    to: Idle
condition: []
action:
  - service: notify.david_text
    data:
      message: Heating Cycle comlete
mode: single

And the state changed, but no message. I did run it manually and got a message.

image

Magenta is Heating Cycle, blue is Idle.

Not sure what I’m doing wrong.

thanks

Are you sure those are the correct states in the dev tools states list? Not that it’s unheard of but typically core integrations don’t capitalize the true states.

the states you see in most of the user interfaces in HA are actually translated states from the true state to “pretty” things up for the user.

even in the history graphs the states there are translated states as well.

I’m pretty sure, as I created the states. Yes, I capitalized them.

I can see them exactly as typed in the developer tools.

And there’s your problem…

you are looking at the “prettified” state for the entity at the top of the states page.

you need to look at actual state listed for the same entity in the bottom table below that.

You will find the “true” state shown there.

Do you mean this?

I checked both places and they are the same.

Here is where I create the status using the REST integration;

rest:
  - scan_interval: 30
    resource: http://192.168.10.246:5000/
    sensor:
      - name: "Heatmaster Boiler Status"
        value_template: "{{ value_json.Heatmaster.status }}"
      - name: "Heatmaster Temperature"
        value_template: "{{ value_json.Heatmaster.temp }}"
        unique_id: heatmaster.temperature
        device_class: temperature
        unit_of_measurement: '°F'      
      - name: "Heatmaster O2"
        value_template: "{{ value_json.Heatmaster.O2 }}"
        unique_id: heatmaster.o2
        unit_of_measurement: "%"
      - name: "Heatmaster Top Air"
        value_template: "{{ value_json.Heatmaster.Top_Air }}"
        unique_id: heatmaster.topair
        unit_of_measurement: "%"
      - name: "Heatmaster Bottom Air"
        value_template: "{{ value_json.Heatmaster.Bottom_Air }}"
        unique_id: heatmaster.bottomair
        unit_of_measurement: "%"

Then in my server that sends the JSON data to HA it looks like this:

                my_dict = {
                    'Heatmaster': {
                        'status': furnace.strip(),
                        'temp': float(param_0),
                        'O2': float(param_1),
                        'Top_Air': float(param_2),
                        'Bottom_Air': float(param_3)
                    }

The ‘status’: furnace.strip() string is either Idle, Bypass, Heating Cycle, or Timer

So I thought that meant the value I would look for matched those strings. I do see in the table Idle and Heating Cycle. So I thought that is what I should be looking for.

I’ll try removing the capitalization to see if that helps.

No that looks like it should be correct.

That falls under the caveat of a “core integration” since you created the sensors using the rest integration it didn’t follow the standard of no capitalization. Which to be clear isn’t an issue. I have several self created sensors that are capitalized.

as long as the state in the table below matches the state in the trigger exactly it should work.

so now that we have that verified as valid then we get back to the original problem…

If I manually set the status to Idle and then Heating Cycle, the automation does trigger and I get my messages.

So it does seem that there is something wrong with the name . . .

Additionally the coloring in the Status history is orange when I did it via developer tools, and magenta when it does it automatically.

Is that expected?

I did see this tho…

you stated this as the goal:

[quote=“Sigogglin, post:1, topic:507422”]
the boiler has moved from Idle to Heating Cycle
[/quote]

but in the automation you have this in the second simplified version:

</s> <s>from: Heating Cycle</s> <s>to: Idle</s> <s>

which is the exact opposite logic.

which one is expected?

never mind. I see it now…

Are you sure that there isn’t a temporary intermediate step that isn’t “Idle”?

if it goes from “Idle” to something else and then to “Heating Cycle” it won’t trigger.

try removing the “from: Idle” requirement from the trigger to see if that works.

Also just an FYI, if you don’t hit the reply button at the bottom of my post or tag me in the reply then I don’t get a notification that you replied to me. I’ll only see it if I happen to look in my unread topics.

Confirm the sensor’s state value doesn’t contain a leading/trailing space character. It shouldn’t, because of furnace.strip(), but best to confirm it.

Copy-paste the following template into the Template Editor and confirm it reports the correct number of characters for the sensor’s value (4 for Idle and 13 for Heating Cycle).

{{ states('sensor.heatmaster_boiler_status') | count }}

EDIT

Correction. It’s ‘heatmaster’ not ‘heating’.

It is currently reporting “Heating Cycle” when I run the template you provided I get 7

that isn’t Heating Cycle :slight_smile:
Is there a way to print what it is getting?

If I do this:
{{ states(‘sensor.heating_boiler_status’) }}

I get unknown

7 characters, but States is reporting Heating Cycle

There was a typo:
I get 13 characters.

and if I remove count I get Heating Cycle, which is 13 characters

That’s due to my mistake. My example contains the wrong sensor name. The name starts with the word heatmaster not heating. I have corrected the example.

13 characters is correct so you have confirmed there are no leading/trailing space characters that could potentially trip up your State Trigger.

I made a new automation that just said state Idle. That did trigger when it went from Heating Cycle to Idle. I at least know that Idle is the correct name :slight_smile:

There are several states, Idle, Heating Cycle, Bypass, Timer, and when things to wrong unknown.

I wanted to have Idle->Heating Cycle specifically. I did change it to just be Heating Cycle, to test if it works like Idle did. Then I can get more complicated.

That definitely sounds as if it goes to some other state between Heating Cycle and Idle.

I would investigate that further.

I tried changing so that when going into the Heating Cycle, to just use To and not From, like I did for Idle.

Doesn’t catch it. Makes me wonder if there is something wrong with having a space in the state name.

try wrapping the state in quotes. I wouldn’t think that was it but it’s something to try.

changing the Heating Cycle to heating_cycle makes it work.

Seems the space isn’t handled properly.

Then that means the true state for that is in lower case with the underscore and not capitalized. Did you check both states and not just Idle?

To clarify. The true state was Heating Cycle with a space. I changed its definition to:

value_template: “{{ value_json.Heatmaster.status | slugify }}”

The slugify changes it lower case and replaces space with underscores. After making that change, I can then use the new state name heating_cycle and it works.

I tried quotes and it doesn’t do anything. I may try backslashing the space, but not sure that will work.

If I can figure out how to make a friendly name of Heating Cycle. I’d be happy. I tried addiing it to the configuration.yaml, but it reported an error.

rest:
  - scan_interval: 10
    resource: http://192.168.10.246:5000/
    sensor:
      - name: "Heatmaster Boiler Status"
        value_template: "{{ value_json.Heatmaster.status | slugify }}"
        friendly_name: 'Heating Cycle'

This gave me an error. Will need to figure out how to do it.