Unable to use "if and" in a thermostat automation

Hi, iìm unable to automate a simple two condition statmen like:
If Temp is >= 20 and climate.riscaldamento is “heat_cool” send me a notify on ios from HA app.

I’m trying to do it with a debug now, but i don’t.

[{"id":"4cd6de59d0b4dd3d","type":"tab","label":"Flow 1","disabled":false,"info":"","env":[]},{"id":"7a975f3fedaff555","type":"poll-state","z":"4cd6de59d0b4dd3d","name":"temp","server":"5342fb6.0acd404","version":2,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"updateinterval":"1","updateIntervalType":"num","updateIntervalUnits":"seconds","outputinitially":false,"outputonchanged":false,"entity_id":"sensor.max_sensor","state_type":"num","halt_if":"20","halt_if_type":"num","halt_if_compare":"gte","outputs":2,"x":170,"y":160,"wires":[["ff03c90b1d9ba978"],[]]},{"id":"28a2e3c2e184a404","type":"debug","z":"4cd6de59d0b4dd3d","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":730,"y":180,"wires":[]},{"id":"a9ea2ff102d84d39","type":"rbe","z":"4cd6de59d0b4dd3d","name":"","func":"rbe","gap":"","start":"","inout":"out","septopics":true,"property":"payload","topi":"topic","x":560,"y":180,"wires":[["28a2e3c2e184a404"]]},{"id":"ff03c90b1d9ba978","type":"function","z":"4cd6de59d0b4dd3d","name":"","func":"if ((msg.payload == \"heat_cool\") && (msg.payload == \"20.5\"))\n{msg.payload == \"Funziona\"}\nelse msg.payload == \"Non funziona\"","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":400,"y":180,"wires":[["a9ea2ff102d84d39"]]},{"id":"d56ff1b250dc63f9","type":"poll-state","z":"4cd6de59d0b4dd3d","name":"Riscaldamento","server":"5342fb6.0acd404","version":2,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"updateinterval":"1","updateIntervalType":"num","updateIntervalUnits":"seconds","outputinitially":false,"outputonchanged":false,"entity_id":"climate.riscaldamento","state_type":"str","halt_if":"heat_cool","halt_if_type":"str","halt_if_compare":"is","outputs":2,"x":140,"y":220,"wires":[["ff03c90b1d9ba978"],[]]},{"id":"5342fb6.0acd404","type":"server","name":"Home Assistant","version":2,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":30}]

How i can solve this? Thank you

edit: how i can format code? sorry

Use three backticks to make the code like this:

[{"id":"3ce6857efbf87fce","type":"api-current-state","z":"4cd6de59d0b4dd3d","name":"","server":"4bbca37b.1700ec","version":2,"outputs":2,"halt_if":"heat_cool","halt_if_type":"str","halt_if_compare":"is","entity_id":"climate.riscaldamento","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"climate.riscaldamento_payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"climate.riscaldamento_data","propertyType":"msg","value":"","valueType":"entity"}],"override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":540,"y":100,"wires":[["28a2e3c2e184a404"],[]]},{"id":"c952ea7064a26460","type":"server-state-changed","z":"4cd6de59d0b4dd3d","name":"","server":"4bbca37b.1700ec","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"sensor.max_sensor","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"20.5","halt_if_type":"num","halt_if_compare":"gte","outputs":2,"output_only_on_state_change":true,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"max_sensor","propertyType":"msg","value":"","valueType":"entityState"},{"property":"max_sensor_data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"max_sensor_topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":220,"y":100,"wires":[["3ce6857efbf87fce"],[]]},{"id":"28a2e3c2e184a404","type":"debug","z":"4cd6de59d0b4dd3d","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":830,"y":100,"wires":[]},{"id":"4bbca37b.1700ec","type":"server","name":"Home Assistant","version":1,"legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

But don’t use poll nodes like that. It’s very inefficient.
And each node creates a message, and these messages can’t be compared like that. They are unaware of eachother.

1 Like

I’ve import your code but no message send when i turn on climate.riscaldamento

Update:
If i use current state it’s not running.
If i use poll is running

:expressionless:

1 Like

Current state is just as the name says, the current state. It doesn’t “run”, it gets “runned”, that is why there is an input and an output.

You really haven’t made it clear what you want to happen or how the automation should run.

I assumed based on your flow, that the temperature was the trigger and the climate was the condition.
What is it you are trying to accomplish?

Yes temp is trigger and climate ON is condition. When sensor reach 20° temp i want a notification on my iphone “The temp is XXX”.

Only this. Thank you

That is what the flow does, not the notification.
But it triggers on 20.5 (I believe it was) and the condition is the climate.

I know but current_state:climate non update when climate,riscaldamento goes on.
And i don’t know why. If i use poll_state, climate.riscaldamento trigger correctly.

I know the function is correct, but i don’t know why my current_state not update correclty

Because there is nothing triggering it.
And there shouldn’t be anything triggering it.

Imagine this:

You only want to walk in the park if it’s sunny and if I ask you.
There is no point of me asking you every second if you want to go for a walk if it’s raining is there?

So, let the trigger be 20 degrees, then and only then do you ask the climate for it’s state.

If you don’t believe me how bad Idea this is then post the notification part of your flow and I will prove to you that polling is not what you want.

Polling means you will get one notification EVERY SECOND until it’s below 20 degrees or the climate is off.

Yup your point is right for me and i don’t want to use polling. Ive just check why if i use “current_state” to trigger the notification, current_state not change. I don’t know why. Ive tried with a light instead and don’t trigger.

As I said before, it doesn’t trigger, it gets triggered.
It’s a condition, not a trigger.

1 Like

Now ive understand and it work! Very than you for your patience