If state is higher/lower than other state

Hello, I made the switch from Domoticz to Home Assistant. In Domoticz you have the fantastic Blockly very simple, now I want to recreate my scripts in NodeRed but that is a lot harder. Someone who can help me? I want to compare two values ​​and go further in the flow based on whether one is higher than the other or vice versa.

What is the easiest way to do such a thing in NodeRed?

This is how I do it in blockly, maybe the image makes it a bit easy to understand what I want

Hi,

OK, I don’t know blocky at all, but I know more on nodered. If i understand what you want (what this script does) : it checks if TempHum in living room is lower than TempHum - Keldermuur AND TempHum - bedroom is lower than TempHum - Keldermuur AND Ede is MORE OR EQUAL than 5 AND TempHum - Living room is lower than TempHum - Basement AND TempHum - bedroom is lower than TempHum - basement THEN you’ll do some action right ?

Sorry, but i need to understand to help :smiley:

If i’m right ont my blocky interpretation i would say that what triggers this script is the TemHum - Living room state.

  • 1st place a “events: state” node with entity “TempHum - Living room” 1st (check output on connect and output on state change)
  • Then connect this to a “current state” node with entity : “TempHum - Keldermuur” and in options of this second node : (entity is an example, fill with the correct one on your setup.)
    image

With this, the second node will have 2 outputs :

  • Upper will be used if the state of “TempHum - Living room” is lower than “TempHum - Keldermuur”.
  • Lower output will be used if it’s equal or higher.

With this, you can continue with the same process with current state nodes till the end of your conditions.
Hopes this is clear and helps :slight_smile:

Note : this will work only if the entities you will use reports the value you need to compare in msg.payload ! msg.payload is the “state” in Home Assistant.
For further help it would be nice to show here what your entities reports in Home Assistant too.

Thank you for your detailed explanation, I understand more about how to compare numbers now :slight_smile:

I will explain a little more about the function of the workflow i want to create.

I have four ventilation switches’ off, 1, 2 and 3 ‘based on different measurements such as’ dew point, temperature, humidity in the house and outside and presence of people, the ventilation will have to adjust to this. it is only about ventilation in the basement so when there is a need to ventilate in the basement or not

I now understand by your example how you should compare one entity state with another and when this is true or false you should go further in the flow or stop. Thanks for that! Next is: what if you want to check multiple states and use them to switch a ventilation position? I will give an example

EXAMPLE 1: This is when the ventilation must be turned off:

IF 
'Living room dewpoint' HIGHER THAN 'basement wall temperature' 
OR 
'Bedroom dewpoint' HIGHER THAN 'basement wall temperature'
OR
'Absolute Humidity in Living room' HIGHER THAN 'Absolute Humidity in basement'
OR
' basement heating power' HIGHER THAN '5' 

SET
Ventilation to Switch off 

I have succeeded in this part, but I have the idea that it can be done more efficiently, see my flow here

[{"id":"27d0d8c6.0767f8","type":"server-state-changed","z":"215c4126.8b02ce","name":"Bedroom Dewpoint","server":"8e9ec046.8c74c","version":1,"entityidfilter":"sensor.bedroom_dewpoint","entityidfiltertype":"exact","outputinitially":true,"state_type":"num","haltifstate":"","halt_if_type":"num","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"x":150,"y":120,"wires":[["4ef8b426.77477c"]]},{"id":"4ef8b426.77477c","type":"api-current-state","z":"215c4126.8b02ce","name":"","server":"8e9ec046.8c74c","version":1,"outputs":2,"halt_if":"payload","halt_if_type":"msg","halt_if_compare":"lt","override_topic":false,"entity_id":"sensor.keldermuur_temperature","state_type":"num","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":480,"y":120,"wires":[["d361d365.35a09"],[]]},{"id":"d361d365.35a09","type":"api-current-state","z":"215c4126.8b02ce","name":"Mechanische Ventilatie Aan?","server":"8e9ec046.8c74c","version":1,"outputs":2,"halt_if":"off","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"input_boolean.mechanische_ventilatie_stand_uit","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":860,"y":120,"wires":[["107d5a94.ccbdb5"],[]]},{"id":"107d5a94.ccbdb5","type":"api-call-service","z":"215c4126.8b02ce","name":"Mechanische Ventilatie Stand Uit","server":"8e9ec046.8c74c","version":1,"service_domain":"input_boolean","service":"turn_on","entityId":"input_boolean.mechanische_ventilatie_stand_uit","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1160,"y":120,"wires":[["5cfac410.26339c"]]},{"id":"5cfac410.26339c","type":"api-call-service","z":"215c4126.8b02ce","name":"","server":"8e9ec046.8c74c","version":1,"service_domain":"notify","service":"pushover","entityId":"","data":"{\"message\":\"Mechanische ventilatie is uitgeschakeld, lucht uit woonkamer condenseert tegen koudste oppervlakte in de kelder\",\"title\":\"Mechanische Ventilatie\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1420,"y":120,"wires":[[]]},{"id":"8130f308.4a238","type":"api-current-state","z":"215c4126.8b02ce","name":"Mechanische Ventilatie Aan?","server":"8e9ec046.8c74c","version":1,"outputs":2,"halt_if":"off","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"input_boolean.mechanische_ventilatie_stand_uit","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":860,"y":60,"wires":[["6729d5b9.fd3cec"],[]]},{"id":"6729d5b9.fd3cec","type":"api-call-service","z":"215c4126.8b02ce","name":"Mechanische Ventilatie Stand Uit","server":"8e9ec046.8c74c","version":1,"service_domain":"input_boolean","service":"turn_on","entityId":"input_boolean.mechanische_ventilatie_stand_uit","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1160,"y":60,"wires":[["c2b86b5d.7bebc8"]]},{"id":"c2b86b5d.7bebc8","type":"api-call-service","z":"215c4126.8b02ce","name":"","server":"8e9ec046.8c74c","version":1,"service_domain":"notify","service":"pushover","entityId":"","data":"{\"message\":\"Mechanische ventilatie is uitgeschakeld, lucht van boven condenseert tegen koudste kelder oppervlakte\",\"title\":\"Mechanische Ventilatie\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1420,"y":60,"wires":[[]]},{"id":"894c4257.d25","type":"server-state-changed","z":"215c4126.8b02ce","name":"Basement Heating Power > 5%","server":"8e9ec046.8c74c","version":1,"entityidfilter":"sensor.basement_heating","entityidfiltertype":"exact","outputinitially":true,"state_type":"num","haltifstate":"5","halt_if_type":"num","halt_if_compare":"gt","outputs":2,"output_only_on_state_change":true,"x":190,"y":240,"wires":[["e1432816.8c5618"],[]]},{"id":"7e39c9c3.e66d38","type":"server-state-changed","z":"215c4126.8b02ce","name":"Living Room Dewpoint","server":"8e9ec046.8c74c","version":1,"entityidfilter":"sensor.livingroom_dewpoint","entityidfiltertype":"exact","outputinitially":true,"state_type":"num","haltifstate":"","halt_if_type":"num","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"x":160,"y":60,"wires":[["a8ffef3f.761ee"]]},{"id":"a8ffef3f.761ee","type":"api-current-state","z":"215c4126.8b02ce","name":"","server":"8e9ec046.8c74c","version":1,"outputs":2,"halt_if":"payload","halt_if_type":"msg","halt_if_compare":"lt","override_topic":false,"entity_id":"sensor.keldermuur_temperature","state_type":"num","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":480,"y":60,"wires":[["8130f308.4a238"],[]]},{"id":"20d0d8d9.8def48","type":"server-state-changed","z":"215c4126.8b02ce","name":"Absolute Humidity Livingroom","server":"8e9ec046.8c74c","version":1,"entityidfilter":"sensor.livingroom_absolutehumidity","entityidfiltertype":"exact","outputinitially":true,"state_type":"num","haltifstate":"","halt_if_type":"num","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"x":180,"y":180,"wires":[["5aab7d7b.aac0e4"]]},{"id":"5aab7d7b.aac0e4","type":"api-current-state","z":"215c4126.8b02ce","name":"","server":"8e9ec046.8c74c","version":1,"outputs":2,"halt_if":"payload","halt_if_type":"msg","halt_if_compare":"lt","override_topic":false,"entity_id":"sensor.basement_absolutehumidity","state_type":"num","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":510,"y":180,"wires":[["b15e8057.cf522"],[]]},{"id":"b15e8057.cf522","type":"api-current-state","z":"215c4126.8b02ce","name":"Mechanische Ventilatie Aan?","server":"8e9ec046.8c74c","version":1,"outputs":2,"halt_if":"off","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"input_boolean.mechanische_ventilatie_stand_uit","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":860,"y":180,"wires":[["2fc23fa0.930c4"],[]]},{"id":"2fc23fa0.930c4","type":"api-call-service","z":"215c4126.8b02ce","name":"Mechanische Ventilatie Stand Uit","server":"8e9ec046.8c74c","version":1,"service_domain":"input_boolean","service":"turn_on","entityId":"input_boolean.mechanische_ventilatie_stand_uit","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1160,"y":180,"wires":[["11a5eb1f.609135"]]},{"id":"11a5eb1f.609135","type":"api-call-service","z":"215c4126.8b02ce","name":"","server":"8e9ec046.8c74c","version":1,"service_domain":"notify","service":"pushover","entityId":"","data":"{\"message\":\"Mechanische ventilatie is uit. De absolute vochtinhoud in de woonkamer is hoger dan in de kelder.\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1420,"y":180,"wires":[[]]},{"id":"e1432816.8c5618","type":"api-current-state","z":"215c4126.8b02ce","name":"Mechanische Ventilatie Aan?","server":"8e9ec046.8c74c","version":1,"outputs":2,"halt_if":"off","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"input_boolean.mechanische_ventilatie_stand_uit","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":860,"y":240,"wires":[["22fba9fe.46f2a6"],[]]},{"id":"22fba9fe.46f2a6","type":"api-call-service","z":"215c4126.8b02ce","name":"Mechanische Ventilatie Stand Uit","server":"8e9ec046.8c74c","version":1,"service_domain":"input_boolean","service":"turn_on","entityId":"input_boolean.mechanische_ventilatie_stand_uit","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1160,"y":240,"wires":[["480da3a8.c601fc"]]},{"id":"480da3a8.c601fc","type":"api-call-service","z":"215c4126.8b02ce","name":"","server":"8e9ec046.8c74c","version":1,"service_domain":"notify","service":"pushover","entityId":"","data":"{\"message\":\"Mechanische ventilatie is uit. De verwarming in de kelder staat aan.\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1420,"y":240,"wires":[[]]},{"id":"8e9ec046.8c74c","type":"server","z":"","name":"Home Assistant"}]

Because the OFF position only works with OR conditions, it is easy.

EXAMPLE 2: Now an example of when the ventilation should switch to position 1, the AND conditions are used here and I don’t know how to use this in NodeRed

IF 
'basement humidty' IS HIGHER THAN '60%'
AND
'Bedroom dewpoint' LOWER THAN 'basement wall temperature' 
AND
'Living room dewpoint' LOWER THAN 'basement wall temperature' 
AND
'Absolute Humidity in Living room' LOWER THAN 'Absolute Humidity in basement'

SET
Ventilation to Switch 1

How do I get this working in NodeRed?

Just checked your 1st flow, seems good so far. You could maybe use only 1 node for Mechanische Ventilatie Aan? and 1 node too for input_boolean.mechanische_ventilatie_stand_uitturn on and only 1 node too for your notification because seems they are exact the same nodes.

For the second i would say :

[{"id":"1b06a4f7.d1ae8b","type":"tab","label":"Flow 2","disabled":false,"info":""},{"id":"752d16e9.3073c8","type":"server-state-changed","z":"1b06a4f7.d1ae8b","name":"","server":"7b44b840.df2a18","version":1,"entityidfilter":"sensor.basement_absolutehumidity","entityidfiltertype":"exact","outputinitially":false,"state_type":"num","haltifstate":"60","halt_if_type":"num","halt_if_compare":"gt","outputs":2,"output_only_on_state_change":true,"x":210,"y":120,"wires":[["9de4a580.ec73b8"],[]]},{"id":"15f3f5f8.aab19a","type":"api-current-state","z":"1b06a4f7.d1ae8b","name":"","server":"7b44b840.df2a18","version":1,"outputs":2,"halt_if":"payload","halt_if_type":"msg","halt_if_compare":"lt","override_topic":true,"entity_id":"sensor.bedroom_dewpoint","state_type":"num","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":1030,"y":120,"wires":[["6b1fd59b.b55b2c"],[]]},{"id":"9de4a580.ec73b8","type":"api-current-state","z":"1b06a4f7.d1ae8b","name":"","server":"7b44b840.df2a18","version":1,"outputs":1,"halt_if":"","halt_if_type":"num","halt_if_compare":"is","override_topic":false,"entity_id":"sensor.basement_wall_temperature","state_type":"num","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":640,"y":120,"wires":[["15f3f5f8.aab19a"]]},{"id":"f6454bff.615d88","type":"api-current-state","z":"1b06a4f7.d1ae8b","name":"","server":"7b44b840.df2a18","version":1,"outputs":2,"halt_if":"payload","halt_if_type":"msg","halt_if_compare":"lt","override_topic":false,"entity_id":"sensor.living_room_dew_point","state_type":"num","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":1040,"y":180,"wires":[["236901f4.e8840e"],[]]},{"id":"6b1fd59b.b55b2c","type":"api-current-state","z":"1b06a4f7.d1ae8b","name":"","server":"7b44b840.df2a18","version":1,"outputs":1,"halt_if":"","halt_if_type":"num","halt_if_compare":"is","override_topic":false,"entity_id":"sensor.basement_wall_temperature","state_type":"num","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":640,"y":180,"wires":[["f6454bff.615d88"]]},{"id":"236901f4.e8840e","type":"api-current-state","z":"1b06a4f7.d1ae8b","name":"","server":"88c826bd.7032f8","version":1,"outputs":2,"halt_if":"payload","halt_if_type":"msg","halt_if_compare":"lt","override_topic":false,"entity_id":"sensor.basement_absolutehumidity","state_type":"num","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":640,"y":240,"wires":[["e7eb0a75.ea9918"],[]]},{"id":"e7eb0a75.ea9918","type":"api-current-state","z":"1b06a4f7.d1ae8b","name":"","server":"7b44b840.df2a18","version":1,"outputs":2,"halt_if":"payload","halt_if_type":"msg","halt_if_compare":"lt","override_topic":false,"entity_id":"sensor.livingroom_absolutehumidity","state_type":"num","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":1060,"y":240,"wires":[[],[]]},{"id":"7b44b840.df2a18","type":"server","z":"","name":"Home Assistant","legacy":false,"hassio":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open"},{"id":"88c826bd.7032f8","type":"server","z":"","name":"Home Assistant"}]

In any condition is not met, this won’t go to the end. Just a remark about this, only basement humidity > 60 will trigger this !
That is a fast try, you have to check it :slight_smile: but it seems good (unless i’m not sure about your entities names !)

Thanks!
The last three blocks indeed appear double but in the last (notify) I have a different text for each.

I am very happy with your workflow of my second example, I think this will work. :slight_smile: I still have to puzzle for a while all those conditions make it very complicated.

Something else:
There is something strange going on, my flow does not want to continue with the first two blocks in my first example

1

  1. State change trigger
    2
  2. Current state

The msg.payload is 13.32 and the current state of 'sensor.keldermuur_temperature is 17.1
The output of the flow always stays false, it doesn’t matter if I choose < lower or > higher in if State

OK found it,

You can’t leave msg.payload for both states.
Change this to msg.payload1 for second current state node for example. Then in this current state node the test will be done between msg.payload (wich comes from the previous state node) and msg.payload1 wich comes from second current state node itself. Then the compare will work.
In fact the current state node will erase the msg.payload with his own state before doing the compare. So that means that if you leave it as is it will always compare to his own value (wich is obviously not what we want to do !).

Just be careful because when this done, the next node will receive the state in msg.payload1 (but in your case you don’t need it !)

Here is a corrected flow :slight_smile:

[{"id":"68079891.653708","type":"server-state-changed","z":"caa234aa.d7bd88","name":"","server":"7b44b840.df2a18","version":1,"entityidfilter":"sensor.basement_absolutehumidity","entityidfiltertype":"exact","outputinitially":false,"state_type":"num","haltifstate":"60","halt_if_type":"num","halt_if_compare":"gt","outputs":2,"output_only_on_state_change":true,"x":210,"y":120,"wires":[["2fedeedd.1e88d2"],[]]},{"id":"29cd6dc6.ff8272","type":"api-current-state","z":"caa234aa.d7bd88","name":"","server":"7b44b840.df2a18","version":1,"outputs":2,"halt_if":"payload","halt_if_type":"msg","halt_if_compare":"lt","override_topic":true,"entity_id":"sensor.bedroom_dewpoint","state_type":"num","state_location":"payload1","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":1030,"y":120,"wires":[["4a08568.a681aa8"],[]]},{"id":"2fedeedd.1e88d2","type":"api-current-state","z":"caa234aa.d7bd88","name":"","server":"7b44b840.df2a18","version":1,"outputs":1,"halt_if":"","halt_if_type":"num","halt_if_compare":"is","override_topic":false,"entity_id":"sensor.basement_wall_temperature","state_type":"num","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":640,"y":120,"wires":[["29cd6dc6.ff8272"]]},{"id":"9898a13d.d7a9d","type":"api-current-state","z":"caa234aa.d7bd88","name":"","server":"7b44b840.df2a18","version":1,"outputs":2,"halt_if":"payload","halt_if_type":"msg","halt_if_compare":"lt","override_topic":false,"entity_id":"sensor.living_room_dew_point","state_type":"num","state_location":"payload1","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":1040,"y":180,"wires":[["2271b3d.3cbbd4c"],[]]},{"id":"4a08568.a681aa8","type":"api-current-state","z":"caa234aa.d7bd88","name":"","server":"7b44b840.df2a18","version":1,"outputs":1,"halt_if":"","halt_if_type":"num","halt_if_compare":"is","override_topic":false,"entity_id":"sensor.basement_wall_temperature","state_type":"num","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":640,"y":180,"wires":[["9898a13d.d7a9d"]]},{"id":"2271b3d.3cbbd4c","type":"api-current-state","z":"caa234aa.d7bd88","name":"","server":"a2de37d5.e33078","version":1,"outputs":2,"halt_if":"payload","halt_if_type":"msg","halt_if_compare":"lt","override_topic":false,"entity_id":"sensor.basement_absolutehumidity","state_type":"num","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":640,"y":240,"wires":[["139c982b.226dc8"],[]]},{"id":"139c982b.226dc8","type":"api-current-state","z":"caa234aa.d7bd88","name":"","server":"7b44b840.df2a18","version":1,"outputs":2,"halt_if":"payload","halt_if_type":"msg","halt_if_compare":"lt","override_topic":false,"entity_id":"sensor.livingroom_absolutehumidity","state_type":"num","state_location":"payload1","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":1060,"y":240,"wires":[[],[]]},{"id":"7b44b840.df2a18","type":"server","z":"","name":"Home Assistant","legacy":false,"hassio":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open"},{"id":"a2de37d5.e33078","type":"server","z":"","name":"Home Assistant"}]

Hope i’m clear lol

4 Likes

Yes! It works! The workflow is now complete and the ventilation works completely autonomously. :slight_smile: Thank you so much for your help and time @SNoof85 I really appreciate it!!

If you or anyone else is curious, let me know, the workflow code is to big to put in a post.

You’re welcome. Enjoy.
And I think that nodered is probably more complex than blocky but possibilities are endless !
It took me some time to correctly understand the logic behind (and I don’t know all possibilities !).
Don’t hesitate to put some debug nodes with complete msg object it is very helpful to understand what’s going on.

I implemented something similar and found an issue with this. Although this flow works, you want to trigger everytime one of the two temperatures changes, not just one. A minor observation