Help on creating an home automation notifying air quality

Hi there, I am new to Node-RED.
I wanted to create an home automation to notify me when the internal pm2.5 is higher than certain level, say >80 for 30 mins, during day time.

Below is my existing setup (first time posting the code here so I hope it worked). However, I would like to ask the following:

  1. How do I improve this automation so that it will announce /notify again after certain time (say 1 hour) if the air quality is still above the threshold?

  2. Further from 1), how do I improve it to announce /notify only if the air quality is worse than the previous check?

Thanks a lot.

code:

[{"id":"66fadf29cf86532a","type":"subflow","name":"Volume Adj 50%","info":"","category":"","in":[{"x":420,"y":240,"wires":[{"id":"eac82526765ddfc9"}]}],"out":[{"x":1180,"y":220,"wires":[{"id":"29de2114963e347f","port":0}]}],"env":[],"meta":{},"color":"#DDAA99"},{"id":"29de2114963e347f","type":"api-call-service","z":"66fadf29cf86532a","g":"f22053755624b07a","name":"Set volume to 50%","server":"ab275ce0.0e1d7","version":5,"debugenabled":false,"domain":"media_player","service":"volume_set","areaId":[],"deviceId":[],"entityId":["media_player.living_room_2"],"data":"{\"volume_level\":0.5}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"data"}],"queue":"none","x":910,"y":220,"wires":[[]]},{"id":"fef2dcc69bd58180","type":"switch","z":"66fadf29cf86532a","g":"f22053755624b07a","name":"50% ?","property":"data.attributes.volume_level","propertyType":"msg","rules":[{"t":"neq","v":"0.5","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":730,"y":220,"wires":[["29de2114963e347f","ad09c5a32fc0fb1a"]]},{"id":"eac82526765ddfc9","type":"api-current-state","z":"66fadf29cf86532a","g":"f22053755624b07a","name":"Speaker","server":"ab275ce0.0e1d7","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"media_player.living_room_2","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"for":0,"forType":"num","forUnits":"minutes","x":580,"y":220,"wires":[["fef2dcc69bd58180"]]},{"id":"ad09c5a32fc0fb1a","type":"function","z":"66fadf29cf86532a","g":"f22053755624b07a","name":"","func":"msg.payload =\n{\n    \"data\":{\n      \"entity_id\":\"media_player.living_room_speaker\",\n      \"volume_level\": msg.data.attributes.volume_level\n    }\n}\nreturn msg;","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":620,"y":320,"wires":[["b4ce0345a5f79159","2ba8cc6a9e41bd1b"]]},{"id":"b4ce0345a5f79159","type":"delay","z":"66fadf29cf86532a","g":"f22053755624b07a","name":"","pauseType":"delay","timeout":"20","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":800,"y":320,"wires":[["bc32f868005ab90e"]]},{"id":"bc32f868005ab90e","type":"api-call-service","z":"66fadf29cf86532a","g":"f22053755624b07a","name":"Set volume to Previous","server":"ab275ce0.0e1d7","version":5,"debugenabled":false,"domain":"media_player","service":"volume_set","areaId":[],"deviceId":[],"entityId":["media_player.living_room_2"],"data":"{\"volume_level\":\"{{msg.payload}}\"}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"data"}],"queue":"none","x":1010,"y":320,"wires":[["c4512046ab4f318a"]]},{"id":"c4512046ab4f318a","type":"debug","z":"66fadf29cf86532a","g":"f22053755624b07a","name":"debug 12","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1000,"y":280,"wires":[]},{"id":"2ba8cc6a9e41bd1b","type":"debug","z":"66fadf29cf86532a","g":"f22053755624b07a","name":"debug 13","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":800,"y":380,"wires":[]},{"id":"f22053755624b07a","type":"group","z":"66fadf29cf86532a","style":{"stroke":"#999999","stroke-opacity":"1","fill":"none","fill-opacity":"1","label":true,"label-position":"nw","color":"#a4a4a4"},"nodes":["29de2114963e347f","fef2dcc69bd58180","eac82526765ddfc9","ad09c5a32fc0fb1a","b4ce0345a5f79159","bc32f868005ab90e","c4512046ab4f318a","2ba8cc6a9e41bd1b"],"x":494,"y":179,"w":652,"h":242},{"id":"8caa74290a4b6db1","type":"api-current-state","z":"a8f290d6aab3d932","name":"current state of PM2.5","server":"ab275ce0.0e1d7","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"sensor.ikea_air_sensor_pm25","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"},{"property":"air_pm","propertyType":"msg","value":"","valueType":"entityState"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":420,"y":200,"wires":[["d47954667195ea24","29403aedb8b65e77"]]},{"id":"75f22ec0d9603bbc","type":"server-state-changed","z":"a8f290d6aab3d932","name":"air quality drops (PM2.5)","server":"ab275ce0.0e1d7","version":5,"outputs":2,"exposeAsEntityConfig":"","entityId":"sensor.ikea_air_sensor_pm25","entityIdType":"exact","outputInitially":false,"stateType":"str","ifState":"80","ifStateType":"num","ifStateOperator":"gt","outputOnlyOnStateChange":true,"for":"30","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":150,"y":160,"wires":[["3589c3d21f6e47a3"],[]]},{"id":"728e1a97eab895a0","type":"api-call-service","z":"a8f290d6aab3d932","name":"TTS current state","server":"ab275ce0.0e1d7","version":5,"debugenabled":true,"domain":"tts","service":"edge_tts_say","areaId":[],"deviceId":[],"entityId":["media_player.living_room_2"],"data":"{\"message\":\"The air quality is poor. PM 2.5 level is at {{air_pm}}, watch out\",\"language\":\"zh-HK-HiuGaaiNeural\",\"options\":{\"rate\":\"-20%\",\"volume\":\"+0%\"}}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":690,"y":280,"wires":[["68cdce0d8cd4f470"]]},{"id":"68cdce0d8cd4f470","type":"debug","z":"a8f290d6aab3d932","name":"debug 6","active":true,"tosidebar":true,"console":true,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":890,"y":280,"wires":[]},{"id":"d47954667195ea24","type":"api-call-service","z":"a8f290d6aab3d932","name":"Notification","server":"ab275ce0.0e1d7","version":5,"debugenabled":false,"domain":"notify","service":"mobile_app_iphone_e","areaId":[],"deviceId":[],"entityId":[],"data":"{\"message\":\"Air quality is poor, the pm2.5 level is at {{payload}}\",\"title\":\"Testing title send\"}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":630,"y":200,"wires":[["23eea19ae4531699"]]},{"id":"23eea19ae4531699","type":"debug","z":"a8f290d6aab3d932","name":"debug 7","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":800,"y":200,"wires":[]},{"id":"29403aedb8b65e77","type":"subflow:66fadf29cf86532a","z":"a8f290d6aab3d932","name":"","x":480,"y":280,"wires":[["728e1a97eab895a0"]]},{"id":"3589c3d21f6e47a3","type":"time-range-switch","z":"a8f290d6aab3d932","name":"Day time","lat":"22.3445","lon":"114.12111","startTime":"10:00","endTime":"21:00","startOffset":0,"endOffset":0,"x":220,"y":220,"wires":[["8caa74290a4b6db1"],[]]},{"id":"ab275ce0.0e1d7","type":"server","name":"Home Assistant","addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"","connectionDelay":false,"cacheJson":false,"heartbeat":false,"heartbeatInterval":"","statusSeparator":"","enableGlobalContextStore":false}]

Create a boolean helper. When the first text is sent the boolean is turned on. When it’s on for an hour send another text. When it sends the text after an hour it turns the boolean off and then on again, resetting the 1 hour waiting period to send another text.

[{"id":"66fadf29cf86532a","type":"subflow","name":"Volume Adj 50%","info":"","category":"","in":[{"x":420,"y":240,"wires":[{"id":"eac82526765ddfc9"}]}],"out":[{"x":1180,"y":220,"wires":[{"id":"29de2114963e347f","port":0}]}],"env":[],"meta":{},"color":"#DDAA99"},{"id":"29de2114963e347f","type":"api-call-service","z":"66fadf29cf86532a","g":"f22053755624b07a","name":"Set volume to 50%","server":"","version":5,"debugenabled":false,"domain":"media_player","service":"volume_set","areaId":[],"deviceId":[],"entityId":["media_player.living_room_2"],"data":"{\"volume_level\":0.5}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"data"}],"queue":"none","x":910,"y":220,"wires":[[]]},{"id":"fef2dcc69bd58180","type":"switch","z":"66fadf29cf86532a","g":"f22053755624b07a","name":"50% ?","property":"data.attributes.volume_level","propertyType":"msg","rules":[{"t":"neq","v":"0.5","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":730,"y":220,"wires":[["29de2114963e347f","ad09c5a32fc0fb1a"]]},{"id":"eac82526765ddfc9","type":"api-current-state","z":"66fadf29cf86532a","g":"f22053755624b07a","name":"Speaker","server":"","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"media_player.living_room_2","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"for":0,"forType":"num","forUnits":"minutes","x":580,"y":220,"wires":[["fef2dcc69bd58180"]]},{"id":"ad09c5a32fc0fb1a","type":"function","z":"66fadf29cf86532a","g":"f22053755624b07a","name":"","func":"msg.payload =\n{\n    \"data\":{\n      \"entity_id\":\"media_player.living_room_speaker\",\n      \"volume_level\": msg.data.attributes.volume_level\n    }\n}\nreturn msg;","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":620,"y":320,"wires":[["b4ce0345a5f79159","2ba8cc6a9e41bd1b"]]},{"id":"b4ce0345a5f79159","type":"delay","z":"66fadf29cf86532a","g":"f22053755624b07a","name":"","pauseType":"delay","timeout":"20","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":800,"y":320,"wires":[["bc32f868005ab90e"]]},{"id":"bc32f868005ab90e","type":"api-call-service","z":"66fadf29cf86532a","g":"f22053755624b07a","name":"Set volume to Previous","server":"","version":5,"debugenabled":false,"domain":"media_player","service":"volume_set","areaId":[],"deviceId":[],"entityId":["media_player.living_room_2"],"data":"{\"volume_level\":\"{{msg.payload}}\"}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"data"}],"queue":"none","x":1010,"y":320,"wires":[["c4512046ab4f318a"]]},{"id":"c4512046ab4f318a","type":"debug","z":"66fadf29cf86532a","g":"f22053755624b07a","name":"debug 12","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1000,"y":280,"wires":[]},{"id":"2ba8cc6a9e41bd1b","type":"debug","z":"66fadf29cf86532a","g":"f22053755624b07a","name":"debug 13","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":800,"y":380,"wires":[]},{"id":"f22053755624b07a","type":"group","z":"66fadf29cf86532a","style":{"stroke":"#999999","stroke-opacity":"1","fill":"none","fill-opacity":"1","label":true,"label-position":"nw","color":"#a4a4a4"},"nodes":["29de2114963e347f","fef2dcc69bd58180","eac82526765ddfc9","ad09c5a32fc0fb1a","b4ce0345a5f79159","bc32f868005ab90e","c4512046ab4f318a","2ba8cc6a9e41bd1b"],"x":494,"y":179,"w":652,"h":242},{"id":"8caa74290a4b6db1","type":"api-current-state","z":"60f2d2277843c698","name":"current state of PM2.5","server":"","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"sensor.ikea_air_sensor_pm25","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"},{"property":"air_pm","propertyType":"msg","value":"","valueType":"entityState"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":2100,"y":2540,"wires":[["d47954667195ea24","29403aedb8b65e77"]]},{"id":"75f22ec0d9603bbc","type":"server-state-changed","z":"60f2d2277843c698","name":"air quality drops (PM2.5)","server":"","version":5,"outputs":2,"exposeAsEntityConfig":"","entityId":"sensor.ikea_air_sensor_pm25","entityIdType":"exact","outputInitially":false,"stateType":"str","ifState":"80","ifStateType":"num","ifStateOperator":"gt","outputOnlyOnStateChange":true,"for":"30","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":1830,"y":2440,"wires":[["3589c3d21f6e47a3","1f74c0d889d476ca"],["f4a810566bbbeb1f"]]},{"id":"728e1a97eab895a0","type":"api-call-service","z":"60f2d2277843c698","name":"TTS current state","server":"","version":5,"debugenabled":true,"domain":"tts","service":"edge_tts_say","areaId":[],"deviceId":[],"entityId":["media_player.living_room_2"],"data":"{\"message\":\"The air quality is poor. PM 2.5 level is at {{air_pm}}, watch out\",\"language\":\"zh-HK-HiuGaaiNeural\",\"options\":{\"rate\":\"-20%\",\"volume\":\"+0%\"}}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":2370,"y":2620,"wires":[["68cdce0d8cd4f470"]]},{"id":"68cdce0d8cd4f470","type":"debug","z":"60f2d2277843c698","name":"debug 6","active":true,"tosidebar":true,"console":true,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":2570,"y":2620,"wires":[]},{"id":"d47954667195ea24","type":"api-call-service","z":"60f2d2277843c698","name":"Notification","server":"","version":5,"debugenabled":false,"domain":"notify","service":"mobile_app_iphone_e","areaId":[],"deviceId":[],"entityId":[],"data":"{\"message\":\"Air quality is poor, the pm2.5 level is at {{payload}}\",\"title\":\"Testing title send\"}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":2310,"y":2540,"wires":[["23eea19ae4531699"]]},{"id":"23eea19ae4531699","type":"debug","z":"60f2d2277843c698","name":"debug 7","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":2480,"y":2540,"wires":[]},{"id":"29403aedb8b65e77","type":"subflow:66fadf29cf86532a","z":"60f2d2277843c698","name":"","x":2160,"y":2620,"wires":[["728e1a97eab895a0"]]},{"id":"3589c3d21f6e47a3","type":"time-range-switch","z":"60f2d2277843c698","name":"Day time","lat":"","lon":"","startTime":"10:00","endTime":"21:00","startOffset":0,"endOffset":0,"x":1900,"y":2540,"wires":[["8caa74290a4b6db1"],[]]},{"id":"1f74c0d889d476ca","type":"api-call-service","z":"60f2d2277843c698","name":"turn on boolean","server":"6b1110b5.183a4","version":5,"debugenabled":false,"domain":"","service":"","areaId":[],"deviceId":[],"entityId":[],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":2140,"y":2400,"wires":[[]]},{"id":"f4a810566bbbeb1f","type":"api-call-service","z":"60f2d2277843c698","name":"turn off boolean","server":"6b1110b5.183a4","version":5,"debugenabled":false,"domain":"","service":"","areaId":[],"deviceId":[],"entityId":[],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":2140,"y":2460,"wires":[[]]},{"id":"ce201989d5f13755","type":"server-state-changed","z":"60f2d2277843c698","name":"boolean on for an hour?","server":"6b1110b5.183a4","version":5,"outputs":2,"exposeAsEntityConfig":"","entityId":"","entityIdType":"exact","outputInitially":false,"stateType":"str","ifState":"on","ifStateType":"str","ifStateOperator":"is","outputOnlyOnStateChange":true,"for":"60","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":1670,"y":2540,"wires":[["3589c3d21f6e47a3","59427c91f1d9104e"],[]]},{"id":"8353a0a9da11957a","type":"api-call-service","z":"60f2d2277843c698","name":"turn on boolean","server":"6b1110b5.183a4","version":5,"debugenabled":false,"domain":"","service":"","areaId":[],"deviceId":[],"entityId":[],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":2140,"y":2680,"wires":[[]]},{"id":"59427c91f1d9104e","type":"api-call-service","z":"60f2d2277843c698","name":"turn off boolean","server":"6b1110b5.183a4","version":5,"debugenabled":false,"domain":"","service":"","areaId":[],"deviceId":[],"entityId":[],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1920,"y":2680,"wires":[["8353a0a9da11957a"]]},{"id":"6b1110b5.183a4","type":"server","name":"Home Assistant","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":false,"heartbeat":false,"heartbeatInterval":"30","areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true}]
1 Like

Thank you so much for replying and editing the flows. It took me a while to figure out why there’s a turn off boolean then turn on boolean. It’s such a smart way to do it.
I only modified one node to put the turn on boolean after the actual notification sent, so that the one hour period would count after the day time.

However, while studying the logic of this, I have a question on the events state node. I have set it to proceed ‘if the state is true’ (over the threshold for 30 mins), I wonder when does it send the signal of ‘if the state is false’ (any time it is below the threshold or it has been below the threshold for 30 mins?)

Event state will fire once when the statement is true. The value must go below the threshold in order for it to reset. If during the wait period the sensor drops below the threshold, it will send out the bottom.

Every time the sensor updates and the statement is false it will send out the bottom. EDIT: it will not wait to send the fail message. So if the sensor updates every 15 sec, it will fire failed every 15 sec.

Continually turning off a boolean that is off really isn’t a problem, the call service is ignored by the system but it’s sloppy.

To deal with that, what we can do is use another event state for the boolean turn off. It will only fire the off command once while the sensor is below the threshold.

image

I’ll take this time to also explain the difference of a trigger node. The trigger node will continue to fire over and over when the condition is true, It does not need to go below the threshold or change state like on to off.

1 Like

Thank you. I had no idea that event state only fire once when the statement is true, but it will keep sending out if the statement is false. It is very tricky.
So in other words, in my case, when the event state fired once when the air is say 81, it won’t do anything again after any time unless it has fell below 80 and rise up again.

I also added your idea about removing that sloppy turn off boolean, and added one with new event state.

Do you mean the trigger state node? Would it be a better option to replace the event state?

[{"id":"66fadf29cf86532a","type":"subflow","name":"Volume Adj 50%","info":"","category":"","in":[{"x":420,"y":240,"wires":[{"id":"eac82526765ddfc9"}]}],"out":[{"x":1180,"y":220,"wires":[{"id":"29de2114963e347f","port":0}]}],"env":[],"meta":{},"color":"#DDAA99"},{"id":"29de2114963e347f","type":"api-call-service","z":"66fadf29cf86532a","g":"f22053755624b07a","name":"Set volume to 50%","server":"ab275ce0.0e1d7","version":5,"debugenabled":false,"domain":"media_player","service":"volume_set","areaId":[],"deviceId":[],"entityId":["media_player.living_room_2"],"data":"{\"volume_level\":0.5}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"data"}],"queue":"none","x":910,"y":220,"wires":[[]]},{"id":"fef2dcc69bd58180","type":"switch","z":"66fadf29cf86532a","g":"f22053755624b07a","name":"50% ?","property":"data.attributes.volume_level","propertyType":"msg","rules":[{"t":"neq","v":"0.5","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":730,"y":220,"wires":[["29de2114963e347f","ad09c5a32fc0fb1a"]]},{"id":"eac82526765ddfc9","type":"api-current-state","z":"66fadf29cf86532a","g":"f22053755624b07a","name":"Speaker","server":"ab275ce0.0e1d7","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"media_player.living_room_2","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"for":0,"forType":"num","forUnits":"minutes","x":580,"y":220,"wires":[["fef2dcc69bd58180"]]},{"id":"ad09c5a32fc0fb1a","type":"function","z":"66fadf29cf86532a","g":"f22053755624b07a","name":"","func":"msg.payload =\n{\n    \"data\":{\n      \"entity_id\":\"media_player.living_room_speaker\",\n      \"volume_level\": msg.data.attributes.volume_level\n    }\n}\nreturn msg;","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":620,"y":320,"wires":[["b4ce0345a5f79159","2ba8cc6a9e41bd1b"]]},{"id":"b4ce0345a5f79159","type":"delay","z":"66fadf29cf86532a","g":"f22053755624b07a","name":"","pauseType":"delay","timeout":"20","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":800,"y":320,"wires":[["bc32f868005ab90e"]]},{"id":"bc32f868005ab90e","type":"api-call-service","z":"66fadf29cf86532a","g":"f22053755624b07a","name":"Set volume to Previous","server":"ab275ce0.0e1d7","version":5,"debugenabled":false,"domain":"media_player","service":"volume_set","areaId":[],"deviceId":[],"entityId":["media_player.living_room_2"],"data":"{\"volume_level\":\"{{msg.payload}}\"}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"data"}],"queue":"none","x":1010,"y":320,"wires":[["c4512046ab4f318a"]]},{"id":"c4512046ab4f318a","type":"debug","z":"66fadf29cf86532a","g":"f22053755624b07a","name":"debug 12","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1000,"y":280,"wires":[]},{"id":"2ba8cc6a9e41bd1b","type":"debug","z":"66fadf29cf86532a","g":"f22053755624b07a","name":"debug 13","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":800,"y":380,"wires":[]},{"id":"f22053755624b07a","type":"group","z":"66fadf29cf86532a","style":{"stroke":"#999999","stroke-opacity":"1","fill":"none","fill-opacity":"1","label":true,"label-position":"nw","color":"#a4a4a4"},"nodes":["29de2114963e347f","fef2dcc69bd58180","eac82526765ddfc9","ad09c5a32fc0fb1a","b4ce0345a5f79159","bc32f868005ab90e","c4512046ab4f318a","2ba8cc6a9e41bd1b"],"x":494,"y":179,"w":652,"h":242},{"id":"41e0dfc3813336bf","type":"api-call-service","z":"a8f290d6aab3d932","name":"turn on boolean","server":"ab275ce0.0e1d7","version":5,"debugenabled":false,"domain":"input_boolean","service":"turn_on","areaId":[],"deviceId":[],"entityId":["input_boolean.air_pm2_5_alert"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":580,"y":1040,"wires":[[]]},{"id":"0e68ba8a42cf9ccb","type":"api-current-state","z":"a8f290d6aab3d932","name":"current state of PM2.5","server":"ab275ce0.0e1d7","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"sensor.ikea_air_sensor_pm25","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"},{"property":"air_pm","propertyType":"msg","value":"","valueType":"entityState"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":620,"y":1080,"wires":[["0b536a92c3dd7c09","673126f20af6084a"]]},{"id":"d8ed826950bae232","type":"server-state-changed","z":"a8f290d6aab3d932","name":"air quality drops (PM2.5) >80","server":"ab275ce0.0e1d7","version":5,"outputs":2,"exposeAsEntityConfig":"","entityId":"sensor.ikea_air_sensor_pm25","entityIdType":"exact","outputInitially":false,"stateType":"str","ifState":"80","ifStateType":"num","ifStateOperator":"gt","outputOnlyOnStateChange":true,"for":"30","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":160,"y":1080,"wires":[["acb178db9029b9bc"],[]]},{"id":"ab7b806e13c35d62","type":"api-call-service","z":"a8f290d6aab3d932","name":"TTS current state","server":"ab275ce0.0e1d7","version":5,"debugenabled":true,"domain":"tts","service":"edge_tts_say","areaId":[],"deviceId":[],"entityId":["media_player.living_room_2"],"data":"{\"message\":\"The air quality is poor. PM 2.5 level is at {{air_pm}}, watch out\",\"language\":\"zh-HK-HiuGaaiNeural\",\"options\":{\"rate\":\"-20%\",\"volume\":\"+0%\"}}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":850,"y":1140,"wires":[[]]},{"id":"0b536a92c3dd7c09","type":"api-call-service","z":"a8f290d6aab3d932","name":"Notification","server":"ab275ce0.0e1d7","version":5,"debugenabled":false,"domain":"notify","service":"mobile_app_iphone_e","areaId":[],"deviceId":[],"entityId":[],"data":"{\"message\":\"Air quality is poor, the pm2.5 level is at {{payload}}\",\"title\":\"Testing title send\"}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":830,"y":1080,"wires":[[]]},{"id":"acb178db9029b9bc","type":"time-range-switch","z":"a8f290d6aab3d932","name":"Day time","lat":"","lon":"","startTime":"10:00","endTime":"21:00","startOffset":0,"endOffset":0,"x":400,"y":1080,"wires":[["0e68ba8a42cf9ccb","41e0dfc3813336bf"],[]]},{"id":"91f3a367c72f0d14","type":"server-state-changed","z":"a8f290d6aab3d932","name":"boolean on for an hour?","server":"ab275ce0.0e1d7","version":5,"outputs":2,"exposeAsEntityConfig":"","entityId":"input_boolean.air_pm2_5_alert","entityIdType":"exact","outputInitially":false,"stateType":"str","ifState":"on","ifStateType":"str","ifStateOperator":"is","outputOnlyOnStateChange":true,"for":"60","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":140,"y":1200,"wires":[["acb178db9029b9bc","61c9b6a3db48c77a"],[]]},{"id":"1414b8f12077f562","type":"api-call-service","z":"a8f290d6aab3d932","name":"turn on boolean","server":"ab275ce0.0e1d7","version":5,"debugenabled":false,"domain":"input_boolean","service":"turn_on","areaId":[],"deviceId":[],"entityId":["input_boolean.air_pm2_5_alert"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":580,"y":1200,"wires":[[]]},{"id":"61c9b6a3db48c77a","type":"api-call-service","z":"a8f290d6aab3d932","name":"turn off boolean","server":"ab275ce0.0e1d7","version":5,"debugenabled":false,"domain":"input_boolean","service":"turn_off","areaId":[],"deviceId":[],"entityId":["input_boolean.air_pm2_5_alert"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":380,"y":1200,"wires":[["1414b8f12077f562"]]},{"id":"673126f20af6084a","type":"subflow:66fadf29cf86532a","z":"a8f290d6aab3d932","name":"","x":640,"y":1140,"wires":[["ab7b806e13c35d62"]]},{"id":"1a55cb9ad886e9c8","type":"server-state-changed","z":"a8f290d6aab3d932","name":"Air quality (PM2.5) <=80","server":"ab275ce0.0e1d7","version":5,"outputs":2,"exposeAsEntityConfig":"","entityId":"sensor.ikea_air_sensor_pm25","entityIdType":"exact","outputInitially":false,"stateType":"str","ifState":"80","ifStateType":"num","ifStateOperator":"lte","outputOnlyOnStateChange":true,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":150,"y":1260,"wires":[["afacb8303fda1fc9"],[]]},{"id":"afacb8303fda1fc9","type":"api-call-service","z":"a8f290d6aab3d932","name":"turn off boolean","server":"ab275ce0.0e1d7","version":5,"debugenabled":false,"domain":"input_boolean","service":"turn_off","areaId":[],"deviceId":[],"entityId":["input_boolean.air_pm2_5_alert"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":380,"y":1260,"wires":[[]]},{"id":"ab275ce0.0e1d7","type":"server","name":"Home Assistant","addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"","connectionDelay":false,"cacheJson":false,"heartbeat":false,"heartbeatInterval":"","statusSeparator":"","enableGlobalContextStore":false}]

No I just figured I’d mention it since it’s the main 2 triggers available in NR for HA entities. The trigger node also does not have a wait(for) option. The event state is the right choice.

Got it. Out of curiosity I have tried the trigger state node and it will really keep firing even the state is under the threshold and at the same level as previous.