Start flow if value is greater then and trigger node if value below

Hi Guys,

I want to have a flow which tells via Alexa-Routine that the room humidty in bathroom drops below 50% (to remember me to close the window after daily showering) but only if it was higher before.

To be honest I’ve no clue how to manage that at the moment. Do you have some hints for me which leads me in the right direction?

This was my starting - but of course this triggers always if humidity changes -->

[{"id":"7bf9c73d.cc7968","type":"server-state-changed","z":"b701708f.d6fa2","name":"Badezimmer Luftfeuchtigkeit <50%","server":"cdcde6c6.b307a8","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"sensor.xiaomi_mija_temperature_01_humidity","entityidfiltertype":"exact","outputinitially":false,"state_type":"num","haltifstate":"50","halt_if_type":"num","halt_if_compare":"lt","outputs":2,"output_only_on_state_change":true,"x":180,"y":60,"wires":[["eee2552d.1736b8"],[]]},{"id":"3f04b7b9.f48ae8","type":"delay","z":"b701708f.d6fa2","name":"","pauseType":"delay","timeout":"7","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":540,"y":60,"wires":[["9d0117db.751c38"]]},{"id":"eee2552d.1736b8","type":"rbe","z":"b701708f.d6fa2","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":410,"y":60,"wires":[["3f04b7b9.f48ae8"]]},{"id":"9d0117db.751c38","type":"alexa-remote-routine","z":"b701708f.d6fa2","name":"","account":"67422e97.c87f7","routineNode":{"type":"speakAtVolume","payload":{"type":"regular","text":{"type":"str","value":"Die Luftfeuchtigkeit im Badezimmer ist wieder unter 50%. Das Fenster kann wieder geschlossen werden."},"volume":{"type":"num","value":"100"},"mode":"set","devices":["G090XG079414118F"]}},"x":750,"y":60,"wires":[[]]},{"id":"cdcde6c6.b307a8","type":"server","z":"","name":"HA (MULATZ)","legacy":false,"hassio":false,"rejectUnauthorizedCerts":false,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true},{"id":"67422e97.c87f7","type":"alexa-remote-account","z":"","name":"Alexa-Account","authMethod":"proxy","proxyOwnIp":"192.168.100.208","proxyPort":"3456","cookieFile":"/root/.node-red/alexa-remote/auth.txt","refreshInterval":"3","alexaServiceHost":"layla.amazon.de","amazonPage":"amazon.de","acceptLanguage":"de-DE","userAgent":"","useWsMqtt":"on","autoInit":"on"}]

The delay is only to give the Alexa-node time to initialize after deployment

Thx in advance for any input!

Cheers
Florian

maybe it should work like this hopefully …

[{"id":"7bf9c73d.cc7968","type":"server-state-changed","z":"b701708f.d6fa2","name":"Badezimmer Luftfeuchtigkeit <50%","server":"cdcde6c6.b307a8","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"sensor.xiaomi_mija_temperature_01_humidity","entityidfiltertype":"exact","outputinitially":false,"state_type":"num","haltifstate":"50","halt_if_type":"num","halt_if_compare":"lt","outputs":2,"output_only_on_state_change":true,"x":180,"y":320,"wires":[["8131ed19.c3484"],[]]},{"id":"9d0117db.751c38","type":"alexa-remote-routine","z":"b701708f.d6fa2","name":"","account":"67422e97.c87f7","routineNode":{"type":"speakAtVolume","payload":{"type":"regular","text":{"type":"str","value":"Die Luftfeuchtigkeit im Badezimmer ist wieder unter 50%. Das Fenster kann wieder geschlossen werden."},"volume":{"type":"num","value":"100"},"mode":"set","devices":["G090XG079414118F"]}},"x":1070,"y":340,"wires":[[]]},{"id":"44de6994.f0f148","type":"change","z":"b701708f.d6fa2","name":"","rules":[{"t":"set","p":"humidity_bathroom","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":620,"y":320,"wires":[["c51708fd.2c3de8"]]},{"id":"8131ed19.c3484","type":"switch","z":"b701708f.d6fa2","name":"","property":"payload","propertyType":"msg","rules":[{"t":"gt","v":"50","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":410,"y":320,"wires":[["44de6994.f0f148"]]},{"id":"c51708fd.2c3de8","type":"ha-wait-until","z":"b701708f.d6fa2","name":"","server":"cdcde6c6.b307a8","outputs":1,"entityId":"sensor.xiaomi_mija_temperature_01_humidity","entityIdFilterType":"exact","property":"attributes.humidity","comparator":"lt","value":"50","valueType":"num","timeout":0,"timeoutType":"num","timeoutUnits":"seconds","entityLocation":"","entityLocationType":"none","checkCurrentState":true,"blockInputOverrides":true,"x":840,"y":320,"wires":[["9d0117db.751c38","c1c65c06.b2622"]]},{"id":"c1c65c06.b2622","type":"change","z":"b701708f.d6fa2","name":"","rules":[{"t":"delete","p":"humidity_bathroom","pt":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":1090,"y":300,"wires":[[]]},{"id":"cdcde6c6.b307a8","type":"server","z":"","name":"HA (MULATZ)","legacy":false,"rejectUnauthorizedCerts":false,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true},{"id":"67422e97.c87f7","type":"alexa-remote-account","z":"","name":"Alexa-Account","authMethod":"proxy","proxyOwnIp":"192.168.100.208","proxyPort":"3456","cookieFile":"/root/.node-red/alexa-remote/auth.txt","refreshInterval":"3","alexaServiceHost":"layla.amazon.de","amazonPage":"amazon.de","acceptLanguage":"de-DE","userAgent":"","useWsMqtt":"on","autoInit":"on"}]

Use a Trigger State node for that:

Hey Marcus,

Do I get it correct that means in words
“If humidity was below [n] before route message through” or what? To be honest I’ve never worked with this node. Can you maybe give a complete example?

Correct, you can use the node to check for
a: Current Message (Value)
b: Previous Message (Value)

Then when it was above 50 before, route the message through. If not, do nothing.

this way ? -->

[{"id":"bc02bbc8.a646f8","type":"trigger-state","z":"b701708f.d6fa2","name":"was below 50% before?","server":"cdcde6c6.b307a8","exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityid":"sensor.xiaomi_mija_temperature_01_humidity","entityidfiltertype":"exact","debugenabled":false,"constraints":[{"id":"mu1l8gqoi3s","targetType":"this_entity","targetValue":"","propertyType":"previous_state","propertyValue":"old_state.state","comparatorType":"<","comparatorValueDatatype":"num","comparatorValue":"50"}],"constraintsmustmatch":"all","outputs":2,"customoutputs":[],"outputinitially":false,"state_type":"num","x":430,"y":300,"wires":[["57cc33cd.680e1c"],[]]},{"id":"b0dcfb78.88d9a8","type":"server-state-changed","z":"b701708f.d6fa2","name":"Humidity Bathroom","server":"cdcde6c6.b307a8","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"sensor.xiaomi_mija_temperature_01_humidity","entityidfiltertype":"exact","outputinitially":true,"state_type":"str","haltifstate":"50","halt_if_type":"num","halt_if_compare":"gt","outputs":2,"output_only_on_state_change":true,"x":190,"y":300,"wires":[["bc02bbc8.a646f8"],[]]},{"id":"b2d016f0.f513b8","type":"debug","z":"b701708f.d6fa2","name":"do_something","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":820,"y":300,"wires":[]},{"id":"57cc33cd.680e1c","type":"ha-wait-until","z":"b701708f.d6fa2","name":"","server":"cdcde6c6.b307a8","outputs":2,"entityId":"sensor.xiaomi_mija_temperature_01_humidity","entityIdFilterType":"exact","property":"attributes.humidity","comparator":"lt","value":"50","valueType":"num","timeout":"90","timeoutType":"num","timeoutUnits":"seconds","entityLocation":"","entityLocationType":"none","checkCurrentState":true,"blockInputOverrides":true,"x":640,"y":300,"wires":[["b2d016f0.f513b8"],[]]},{"id":"cdcde6c6.b307a8","type":"server","z":"","name":"HA (MULATZ)","legacy":false,"rejectUnauthorizedCerts":false,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

image

You do not need the extra Events State Node. The Trigger node can work on its own.
And you should in that case also add the condition that current state is the value you want.

ok thx for your info - I’ll try it that way - will check if it’s working today in the evening if the first of take a shower :wink:

Thx indeed!

FYI… your current node condition is that the previous state was below 50. I understood that you want to only turn it on if it falls below 50 (current state) but only if it was higher than 50 (previous state).
And Im not sure what the wait node is supposed to do?

Yes - do I have a fallacy? I would have to have following logic in words:

Humidty is normally below 50% in bathroom. When somebody goes showering - it rises above until ~ 80%. The last one in bathroom opens the window after showering to get fresh air again. The Flow should trigger a notification when the humidity falls down below 50% again.

Do it like this then:


image

That should work fine

hmm not really sure if I got it - but I’ll try it this way and will report if it worked then …
Thx!

So lets go through the options:

This entity’s current state <=50 - Means it will only trigger if the current state is equal or below 50
This entity’s previous state >50 - Means it will only trigger if the previous state was above 50

Both conditions need to be met to get an output

You can manually test it with the inject node:
image

Simply send the states to the node. And check if it triggers as expected.

ok got it :slight_smile:
will tell if working!

Unfortunately, that did not work. - Not sure why currently …

Thx

PS: I guess I know why … :wink:
image

Unfortunately it didn’t trigger at all :frowning: . I’m helpless …

[{"id":"27d9fb18.6c6744","type":"trigger-state","z":"dc403160.530cb","name":"was above 70% before?","server":"cdcde6c6.b307a8","exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityid":"sensor.xiaomi_mija_temperature_01_humidity","entityidfiltertype":"exact","debugenabled":false,"constraints":[{"id":"uhu54c5k6s","targetType":"this_entity","targetValue":"","propertyType":"current_state","propertyValue":"new_state.state","comparatorType":"<=","comparatorValueDatatype":"num","comparatorValue":"50"},{"id":"eodn3kmrxa","targetType":"this_entity","targetValue":"","propertyType":"previous_state","propertyValue":"old_state.state","comparatorType":">","comparatorValueDatatype":"num","comparatorValue":"70"}],"constraintsmustmatch":"all","outputs":2,"customoutputs":[],"outputinitially":false,"state_type":"num","x":310,"y":840,"wires":[["33557984.425386","3fb66457.3622ac","9105d947.a442c8"],[]]},{"id":"33557984.425386","type":"debug","z":"dc403160.530cb","name":"true constraint","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":560,"y":800,"wires":[]},{"id":"3fb66457.3622ac","type":"api-call-service","z":"dc403160.530cb","name":"notify via Mobile","server":"cdcde6c6.b307a8","version":1,"debugenabled":false,"service_domain":"notify","service":"mobile_app_iphone_bofh","entityId":"","data":"{\"title\":\"HomeAssistant\",\"message\":\"Fenster im Badezimmer schließen\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":560,"y":880,"wires":[[]]},{"id":"f59d85f3.079f28","type":"inject","z":"dc403160.530cb","name":"","topic":"","payload":"{\"entity_id\":\"sensor.xiaomi_mija_temperature_01_humidity\",\"old_state\":{\"state\":80},\"new_state\":{\"state\":49}}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":840,"wires":[["27d9fb18.6c6744"]]},{"id":"3e66e5e9.5c5bda","type":"poll-state","z":"dc403160.530cb","name":"is TV on?","server":"cdcde6c6.b307a8","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"updateinterval":"60","updateIntervalUnits":"seconds","outputinitially":true,"outputonchanged":true,"entity_id":"media_player.sony_bravia_tv","state_type":"str","halt_if":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"x":100,"y":940,"wires":[["f04f9c77.78e39","c2d0f81a.30fc58"]]},{"id":"f04f9c77.78e39","type":"debug","z":"dc403160.530cb","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":270,"y":960,"wires":[]},{"id":"c2d0f81a.30fc58","type":"change","z":"dc403160.530cb","name":"set status to global_variable","rules":[{"t":"set","p":"tv_on","pt":"global","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":920,"wires":[[]]},{"id":"9105d947.a442c8","type":"switch","z":"dc403160.530cb","name":"","property":"tv_on","propertyType":"global","rules":[{"t":"eq","v":"on","vt":"str"},{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":530,"y":840,"wires":[["f3cc1540.3e6f88"],["bb5ed1b3.72fb"]]},{"id":"f3cc1540.3e6f88","type":"api-call-service","z":"dc403160.530cb","name":"notify via AndroidTV","server":"cdcde6c6.b307a8","version":1,"debugenabled":false,"service_domain":"notify","service":"wohnzimmer_nf","entityId":"","data":"{\"title\":\"HomeAssistant\",\"message\":\"Fenster im Badezimmer schließen\",\"data\":{\"fontsize\":\"large\",\"position\":\"center\",\"duration\":20}}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":900,"y":800,"wires":[[]]},{"id":"bb5ed1b3.72fb","type":"alexa-remote-routine","z":"dc403160.530cb","name":"","account":"67422e97.c87f7","routineNode":{"type":"speakAtVolume","payload":{"type":"regular","text":{"type":"str","value":"Fenster im Badezimmer schließen"},"volume":{"type":"num","value":"70"},"mode":"set","devices":["G090XG079414118F"]}},"x":910,"y":880,"wires":[[]]},{"id":"cdcde6c6.b307a8","type":"server","z":"","name":"HA (MULATZ)","legacy":false,"rejectUnauthorizedCerts":false,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true},{"id":"67422e97.c87f7","type":"alexa-remote-account","z":"","name":"Alexa-Account","authMethod":"proxy","proxyOwnIp":"192.168.100.208","proxyPort":"3456","cookieFile":"/root/.node-red/alexa-remote/auth.txt","refreshInterval":"3","alexaServiceHost":"layla.amazon.de","amazonPage":"amazon.de","acceptLanguage":"de-DE","userAgent":"","useWsMqtt":"on","autoInit":"on"}]

image

Why so complicated? Do you want Alexa to remind you exactly when it drops below 50% (independent where you are), or if you open the door of your bathroom ? I have the same thing, but I just remind myself via Alexa when I open the door, and the window is still open.

If you want it just one time after it drops under 50%, why don’t you just template a binary sensor? Define this binary sensor as “on” if your humidity is over 50%, and “off” if its below. Than you can use the trigger node again, like in your example earlier… since the values of the templated binary_sensor don’t change anymore, it will handle this problem as expected. I do a lot of stuff with this method, and its working perfect.

I dont know how you implemented your Xiaomi Sensors. But mine do not report humidty as a number value, but actually as a string. So maybe check if thats the same for you. You can easily see it in the debug node. If its a string, the text will have the same color as the normal text. If its a number it will show without “” and with a different color. A Screenshot as an example:

In that case, you may need to use a function node to parse the value as a number.

@fitim: Hey I want to remember myself to close the window (nobody is in the bathroom anymore in this situation).
Can you maybe give an example of such a template? I’m currently not really familiar with the syntax.

@AlmostSerious: My sensors DO report numbers, not strings. When I inject the test node - the flow works - but not without. Maybe the state-trigger node does not get updated properly?

Cheers

- platform: template
  sensor:
    badezimmerlueftung_notwendig:
      friendly_name: "Badezimmerlüftung notwendig"
      value_template: "{{ states('sensor.HUMIDITY')|float > 50}}"

This should be your sensor, wich is on when the humidity is over 50 %, and off when its below.

To node-red you do the following thing then:

[{"id":"49356e4a.d9683","type":"trigger-state","z":"64a902bf.cb4a94","name":"","server":"784056aa.7a3528","exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityid":"binary_sensor.badezimmerlueftung_notwendig","entityidfiltertype":"exact","debugenabled":false,"constraints":[],"constraintsmustmatch":"all","outputs":3,"customoutputs":[{"outputId":"nqxjid2q4kk","messageType":"default","messageValue":"","messageValueType":"json","comparatorPropertyType":"current_state","comparatorPropertyValue":"new_state.state","comparatorType":"is","comparatorValue":"off"}],"outputinitially":false,"state_type":"str","x":320,"y":500,"wires":[[],[],["2d3fe8a7.4e4cd8"]]},{"id":"fb40d1b2.e075a8","type":"api-call-service","z":"64a902bf.cb4a94","name":"","server":"","version":1,"debugenabled":false,"service_domain":"","service":"","entityId":"","data":"","dataType":"json","mergecontext":null,"output_location":"payload","output_location_type":"none","mustacheAltTags":false,"x":1070,"y":500,"wires":[[]]},{"id":"2d3fe8a7.4e4cd8","type":"api-current-state","z":"64a902bf.cb4a94","name":"","server":"784056aa.7a3528","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"binary_sensor.badezimmerfenster","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":780,"y":500,"wires":[["fb40d1b2.e075a8"],[]]},{"id":"50013462.f5380c","type":"comment","z":"64a902bf.cb4a94","name":"trigger for the templated sensor","info":"","x":350,"y":440,"wires":[]},{"id":"a6bc3b80.0e4e8","type":"comment","z":"64a902bf.cb4a94","name":"check if the window is still open?","info":"","x":790,"y":460,"wires":[]},{"id":"374ee9ae.98f31e","type":"comment","z":"64a902bf.cb4a94","name":"call your service","info":"","x":1070,"y":460,"wires":[]},{"id":"784056aa.7a3528","type":"server","z":"","name":"Home Assistant"}]

Have fun with it. You just need to replace the humidity sensor with your sensor in the templated sensor, and the entities in node red. I have commented the node red flow for you. Everything else should be done.