Hello folks, this is my 1st post
I have looked around for days but I was not able to find useful suggestion.
Apparently I have a silly problem.
I own a water purifier and any time the water tap is opened an automation turn on the UV lamp which will kill possible bacteria.
This automation is because I don't want the UV always ON, as it was on the original system, to save electricity.
Now the issue. Sometimes, opening and closing repeatedly the tap, the system measure the power consumption when the lamp is OFF reporting that the lamp is broken.
This is a bug and I'm not able to read the sensor only when the LAMP is only ON!!!
I mean, I want to drop the measurement if the lamp is off.
How can I do it?
Ideally I would do something like:
//// pseudo code ////
var boolean isLampOn;
var power_consumption;
if (isLampOn) {
wait 3 sec; // this waiting time is necessary to let the measurement be stable.
power_consumption = read_sensor();
} else {
return;
}
if (power_consumption < 5w ){
send_alexa_alert('Please check UV lamp');
} else {
return;
}
////////////////////
On Node red I made a complex flow, using even the gate node and playing with waiting time but still I-m not able to do it properly.
Here my flow:
[{"id":"c3a0f328cb151d3a","type":"tab","label":"Lampada UV","disabled":false,"info":"Verifica che l'assorbimento di potenza quando è accesa.\nNormalmente assorbe circa 12W.\nSe l'assorbimento è < 5W manda un messaggio telegram per avvisare di controllarne lo stato."},{"id":"52bf50a672470ef1","type":"api-call-service","z":"c3a0f328cb151d3a","name":"Notifica Telegram di verifica","server":"19ed11da.49f22e","version":3,"debugenabled":false,"service_domain":"telegram_bot","service":"send_message","entityId":"","data":"{\t \"title\":\"Lampada UV:\",\t \"message\": \"Assorbimento = \" & msg.payload & \"W.\\nVerificare lo stato della lampada.\"\t}","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":600,"y":420,"wires":[[]]},{"id":"162d12da4a6d6b82","type":"api-call-service","z":"c3a0f328cb151d3a","name":"Notifica Alexa di Verifica","server":"19ed11da.49f22e","version":3,"debugenabled":false,"service_domain":"notify","service":"alexa_media","entityId":"","data":"{\"message\":\"Verificare la Lampada del depuratore\",\"data\":{\"type\":\"announce\",\"method\":\"spoken\"},\"target\":\"media_player.echo_dot_cucina\"}","dataType":"json","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":590,"y":480,"wires":[[]]},{"id":"03db512d3e8c0892","type":"inject","z":"c3a0f328cb151d3a","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":100,"y":280,"wires":[["68da5a1212142c93"]]},{"id":"af5586fa2930987b","type":"delay","z":"c3a0f328cb151d3a","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":640,"y":200,"wires":[["77be12e4ec2ebbea"]]},{"id":"94f77e3830c366b7","type":"api-current-state","z":"c3a0f328cb151d3a","name":"Consumo Lamp 10 sec < 5W","server":"19ed11da.49f22e","version":3,"outputs":2,"halt_if":"5","halt_if_type":"num","halt_if_compare":"lt","entity_id":"sensor.consumo_lampada_uv","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":0,"forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":160,"y":540,"wires":[["52bf50a672470ef1","162d12da4a6d6b82","06eeebac93870e9d","fc4e62968c729957"],["06eeebac93870e9d","fc4e62968c729957","361e86823e56c07d"]]},{"id":"06eeebac93870e9d","type":"mqtt out","z":"c3a0f328cb151d3a","name":"","topic":"home/uvlamp/power","qos":"","retain":"true","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"ae202893.c26c1","x":580,"y":540,"wires":[]},{"id":"fc4e62968c729957","type":"api-call-service","z":"c3a0f328cb151d3a","name":"Spegni UV dopo misura","server":"19ed11da.49f22e","version":3,"debugenabled":false,"service_domain":"switch","service":"turn_off","entityId":"switch.lampada_uv","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":590,"y":660,"wires":[[]]},{"id":"ac88cb78bb26b2fd","type":"api-call-service","z":"c3a0f328cb151d3a","name":"Manda MSG Ok","server":"19ed11da.49f22e","version":3,"debugenabled":false,"service_domain":"telegram_bot","service":"send_message","entityId":"","data":"{\t \"title\":\"Lampada UV: controllo.\",\t \"message\": \"Assorbimento = \" & msg.payload & \"W\"\t}","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":560,"y":600,"wires":[[]]},{"id":"32cb64055afc4461","type":"comment","z":"c3a0f328cb151d3a","name":"Detached mode","info":"Lo shelly lampada UV è configurato in detached mode per lasciare il controllo del relè esclusivamente a node-red","x":120,"y":40,"wires":[]},{"id":"89e844fd7ea09f3f","type":"mqtt in","z":"c3a0f328cb151d3a","name":"UV Input","topic":"shellies/shellyswitch25-8CAAB505B075/input/0","qos":"2","datatype":"auto","broker":"ae202893.c26c1","nl":false,"rap":true,"rh":0,"inputs":0,"x":100,"y":100,"wires":[["970591f51057ba35"]]},{"id":"e661b370d328f79d","type":"api-call-service","z":"c3a0f328cb151d3a","name":"UV Turn On","server":"19ed11da.49f22e","version":3,"debugenabled":false,"service_domain":"switch","service":"turn_on","entityId":"switch.lampada_uv","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":650,"y":60,"wires":[[]]},{"id":"0975904219c72046","type":"switch","z":"c3a0f328cb151d3a","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"num"},{"t":"eq","v":"0","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":450,"y":100,"wires":[["e661b370d328f79d","5835e4a0948f869c"],["af5586fa2930987b","4735085d467372d0"]]},{"id":"361e86823e56c07d","type":"debug","z":"c3a0f328cb151d3a","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":910,"y":360,"wires":[]},{"id":"970591f51057ba35","type":"rbe","z":"c3a0f328cb151d3a","name":"","func":"rbei","gap":"","start":"","inout":"out","septopics":true,"property":"payload","topi":"topic","x":270,"y":100,"wires":[["0975904219c72046"]]},{"id":"0af3fc564e13f0ef","type":"comment","z":"c3a0f328cb151d3a","name":"Logga ultimo consumo","info":"Solo a scopo informativo loggo via mqtt l'ultimo consumo misurato.","x":820,"y":540,"wires":[]},{"id":"399d7d07cf4a3aac","type":"comment","z":"c3a0f328cb151d3a","name":"Filtro","info":"Lascia passare il messaggio mqtt solo se cambia stato.","x":270,"y":40,"wires":[]},{"id":"5b143bfafd654df3","type":"comment","z":"c3a0f328cb151d3a","name":"Spegni UV","info":"Dopo la misura spegni la lampada.","x":540,"y":720,"wires":[]},{"id":"68da5a1212142c93","type":"api-call-service","z":"c3a0f328cb151d3a","name":"UV Turn On","server":"19ed11da.49f22e","version":3,"debugenabled":false,"service_domain":"switch","service":"turn_on","entityId":"switch.lampada_uv","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":250,"y":280,"wires":[[]]},{"id":"dccae971881b8b1a","type":"inject","z":"c3a0f328cb151d3a","name":"Turn ON","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"str","x":100,"y":160,"wires":[["0975904219c72046"]]},{"id":"831e1ee19ff37926","type":"inject","z":"c3a0f328cb151d3a","name":"Turn OFF","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"0","payloadType":"str","x":100,"y":200,"wires":[["0975904219c72046"]]},{"id":"77be12e4ec2ebbea","type":"gate","z":"c3a0f328cb151d3a","name":"","controlTopic":"control","defaultState":"open","openCmd":"open","closeCmd":"close","toggleCmd":"toggle","defaultCmd":"default","statusCmd":"status","persist":false,"storeName":"memory","x":830,"y":160,"wires":[["94f77e3830c366b7","361e86823e56c07d"]]},{"id":"5835e4a0948f869c","type":"change","z":"c3a0f328cb151d3a","name":"Close","rules":[{"t":"set","p":"topic","pt":"msg","to":"control","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"close","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":630,"y":120,"wires":[["77be12e4ec2ebbea"]]},{"id":"8a0d3f59fe39b4ac","type":"inject","z":"c3a0f328cb151d3a","name":"Close Gate","props":[{"p":"topic","vt":"str"},{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"Control","payload":"close","payloadType":"str","x":520,"y":300,"wires":[[]]},{"id":"4735085d467372d0","type":"change","z":"c3a0f328cb151d3a","name":"Open","rules":[{"t":"set","p":"topic","pt":"msg","to":"control","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"open","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":630,"y":160,"wires":[["77be12e4ec2ebbea"]]},{"id":"19ed11da.49f22e","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},{"id":"ae202893.c26c1","type":"mqtt-broker","name":"home-assistant-mqtt-addon","broker":"192.168.1.11","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]
ADMIN Note: Use triple backticks above and below flows and code to prevent forum formatting corrupting the code.