xoseperez / node-red-contrib-power-monitor

A Node-RED node to monitor home appliances based on their power consumption.
Other
21 stars 16 forks source link

Stop after X time #10

Open dvine2000 opened 3 years ago

dvine2000 commented 3 years ago

First of all great power monitor. I just starting to migrate my fibaro LUA scene's to HA with node red.

It's always hard to monitor these powers.

For my case the start works fine but the stopping is hard. My washing machine bumps to 0w with not on all programms the same amount so one time the monitors stops send the payload good and other times it won't stop and no payload is sending.

My suggestion for the stopping is a time setting added. So when you put in 5 min. it's waiting that 0W is there for 5 min. before putting the power monitor to stop

Running my Fibaro scene for 7 years with this waiting stop timer and never had problems.

xoseperez commented 3 years ago

Hi If you set the stop threshold to 0W and the "stop after" value to 5, assuming you are feeding the node values every minute, it will trigger the stop event after 5 minutes of 0W readings. If there is any non-0W reading during those 5 minutes the stop counter will be reset. You are explicitly asking the node to trigger the event only after 0W readings in a row.

dvine2000 commented 3 years ago

Maybe I didn't explain good enough what I meant and want.

Stop after: Number of messages with readings below the threshold to trigger a stop event. I want stop after: X time below the threshold to trigger a stop event

In my case when things ending washing machine bumps 10 to 20 times to 0W and goes up to like 50 wats before the program stops and it's stay's 0W even in the middle of the program it goes to 0W a few times. (sorry for the A+++ washing machine) Dryer bumps maybe like 30 times to 2.4W (from 2.4 to 40W) every time before it's ending and stays at 2.4W

So when set stop after 1 it's stopping the first time what you don't want and with 2 or more it never stops because of the reset

But I can't judge a stop message amount because this is not a default value on my washing machine or dryer. And because of the reset function the monitor wont stop.

So that's why I asked for a extra function in the power monitor with a stop timer instead or next to messages amount so you can choose witch one you want. But I can sure you a stop after X time if below threshold X watts will always works. This way it's much easier to set a value that will always work without a complete analyse of your power usage of the dryer

xoseperez commented 3 years ago

I understand you are not feeding the node with power readings from the washing machine at regular intervals, then. Am I right? That's why you need a timer instead?

dvine2000 commented 3 years ago

No I feed the power monitor with my dryer or washing machine. Start threshold on 100 start after 1

and for now I used stop threshold 0 stop after 1

I made a own trigger if below 3W for 5 Min then power down wall plug. Power gets to 0 first time and the power monitor is get his first and only needed stop command. after that I get a telegram message.

I tried several settings like stop threshold 3 with stop after 1 or 2 or even 5 or more but or the stop command comes to quickly or it doesn't stop.

here is my flow that is working at this moment.

[{"id":"f0f855afd97ea0f1","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"2bfddcea1f6d2b59","type":"switch","z":"f0f855afd97ea0f1","name":"event stop","property":"payload.event","propertyType":"msg","rules":[{"t":"eq","v":"stop","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":490,"y":100,"wires":[["8017a92c3f2f59e4"]]},{"id":"3aed0d75ea886a4f","type":"power-monitor","z":"f0f855afd97ea0f1","name":"Wasmachine","startthreshold":"100","stopthreshold":"0","startafter":"1","stopafter":"1","x":290,"y":100,"wires":[["2bfddcea1f6d2b59","dc19a8dab83354a2"]]},{"id":"66d29146c38795ca","type":"telegram sender","z":"f0f855afd97ea0f1","name":"Tom telegram","bot":"b09bd14a.b601d","haserroroutput":false,"outputs":1,"x":1200,"y":100,"wires":[[]]},{"id":"8017a92c3f2f59e4","type":"function","z":"f0f855afd97ea0f1","name":"","func":"msg.payload.time = Math.round(msg.payload.time / 60);\nmsg.payload.cost = (msg.payload.energy * 0.211356).toFixed(2);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":680,"y":100,"wires":[["68e180b8adba0439"]]},{"id":"68e180b8adba0439","type":"template","z":"f0f855afd97ea0f1","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"De {{ payload.name }} is klaar\nTotale tijd: {{ payload.time }} min.\nTotaal vebruik : {{ payload.energy }} kWh\nKosten wasbeurt: € {{ payload.cost }}","output":"str","x":840,"y":100,"wires":[["6c1ab43790232680","dcb3351bf52a8a6d"]]},{"id":"41254c5b5b26394e","type":"server-state-changed","z":"f0f855afd97ea0f1","name":"Wasmachine","server":"85cb4144.a30f7","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"sensor.wasmachine_sensor_current","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"num","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"for":"0","forType":"num","forUnits":"seconds","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"}],"x":90,"y":100,"wires":[["3aed0d75ea886a4f","2a43d1299dfd5e48"]]},{"id":"6c1ab43790232680","type":"function","z":"f0f855afd97ea0f1","name":"","func":"msg.payload =\n{\n chatId: '46597978',\n type: 'message',\n content: msg.payload\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1020,"y":100,"wires":[["66d29146c38795ca"]]},{"id":"dc19a8dab83354a2","type":"switch","z":"f0f855afd97ea0f1","name":"start","property":"payload.event","propertyType":"msg","rules":[{"t":"eq","v":"start","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":470,"y":60,"wires":[["b7814a466a594104","476c4a7b3885192f"]]},{"id":"b7814a466a594104","type":"function","z":"f0f855afd97ea0f1","name":"","func":"msg.payload = {\n \"chatId\": \"46597978\", \n \"type\":\"message\", \n \"content\":\n \"**Wasmachine is AAN**\"\n};\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1020,"y":60,"wires":[["66d29146c38795ca"]]},{"id":"cfea68eb8f8c76e0","type":"telegram sender","z":"f0f855afd97ea0f1","name":"Patricia Telegram","bot":"16bc1ccd.414d73","haserroroutput":false,"outputs":1,"x":1210,"y":160,"wires":[[]]},{"id":"476c4a7b3885192f","type":"function","z":"f0f855afd97ea0f1","name":"","func":"msg.payload = {\n \"chatId\": \"205329462\", \n \"type\":\"message\", \n \"content\":\n \"**Wasmachine is AAN**\"\n};\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1020,"y":160,"wires":[["cfea68eb8f8c76e0"]]},{"id":"dcb3351bf52a8a6d","type":"function","z":"f0f855afd97ea0f1","name":"","func":"msg.payload =\n{\n chatId: '205329462',\n type: 'message',\n content: msg.payload\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1020,"y":200,"wires":[["cfea68eb8f8c76e0"]]},{"id":"04558608241aad7b","type":"switch","z":"f0f855afd97ea0f1","name":"event stop","property":"payload.event","propertyType":"msg","rules":[{"t":"eq","v":"stop","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":490,"y":420,"wires":[["f2e51284b39a8023"]]},{"id":"41605ae1e4abe96c","type":"power-monitor","z":"f0f855afd97ea0f1","name":"Droger","startthreshold":"65","stopthreshold":"0","startafter":"1","stopafter":"1","x":270,"y":420,"wires":[["04558608241aad7b","458d18dac5d3b48d"]]},{"id":"07f35c9789cce309","type":"telegram sender","z":"f0f855afd97ea0f1","name":"Tom telegram","bot":"b09bd14a.b601d","haserroroutput":false,"outputs":1,"x":1200,"y":420,"wires":[[]]},{"id":"f2e51284b39a8023","type":"function","z":"f0f855afd97ea0f1","name":"","func":"msg.payload.time = Math.round(msg.payload.time / 60);\nmsg.payload.cost = (msg.payload.energy * 0.211356).toFixed(2);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":680,"y":420,"wires":[["98c27c9261df47bb"]]},{"id":"98c27c9261df47bb","type":"template","z":"f0f855afd97ea0f1","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"De {{ payload.name }} is klaar\nTotale tijd: {{ payload.time }} min.\nTotaal vebruik : {{ payload.energy }} kWh\nKosten wasbeurt: € {{ payload.cost }}","output":"str","x":840,"y":420,"wires":[["596c0179655e4d9d","af7e3a9785408d0e"]]},{"id":"dddbc87255e277d8","type":"server-state-changed","z":"f0f855afd97ea0f1","name":"Droger","server":"85cb4144.a30f7","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"sensor.droger_sensor_current","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"num","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"for":"0","forType":"num","forUnits":"seconds","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"}],"x":70,"y":420,"wires":[["41605ae1e4abe96c","b7fe6075aea4d17a"]]},{"id":"596c0179655e4d9d","type":"function","z":"f0f855afd97ea0f1","name":"","func":"msg.payload =\n{\n chatId: '46597978',\n type: 'message',\n content: msg.payload\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1020,"y":420,"wires":[["07f35c9789cce309"]]},{"id":"458d18dac5d3b48d","type":"switch","z":"f0f855afd97ea0f1","name":"start","property":"payload.event","propertyType":"msg","rules":[{"t":"eq","v":"start","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":470,"y":380,"wires":[["d16e9325cd820b90","bc9ef17b8dbff8f5"]]},{"id":"d16e9325cd820b90","type":"function","z":"f0f855afd97ea0f1","name":"","func":"msg.payload = {\n \"chatId\": \"46597978\", \n \"type\":\"message\", \n \"content\":\n \"**Droger is AAN**\"\n};\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1020,"y":380,"wires":[["07f35c9789cce309"]]},{"id":"5620a269cd7e55b2","type":"telegram sender","z":"f0f855afd97ea0f1","name":"Patricia Telegram","bot":"16bc1ccd.414d73","haserroroutput":false,"outputs":1,"x":1210,"y":480,"wires":[[]]},{"id":"bc9ef17b8dbff8f5","type":"function","z":"f0f855afd97ea0f1","name":"","func":"msg.payload = {\n \"chatId\": \"205329462\", \n \"type\":\"message\", \n \"content\":\n \"**Droger is AAN**\"\n};\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1020,"y":460,"wires":[["5620a269cd7e55b2"]]},{"id":"af7e3a9785408d0e","type":"function","z":"f0f855afd97ea0f1","name":"","func":"msg.payload =\n{\n chatId: '205329462',\n type: 'message',\n content: msg.payload\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1020,"y":520,"wires":[["5620a269cd7e55b2"]]},{"id":"51ceefbc4adb26af","type":"api-call-service","z":"f0f855afd97ea0f1","name":"Wasmachine Off","server":"85cb4144.a30f7","version":3,"debugenabled":false,"service_domain":"switch","service":"turn_off","entityId":"switch.was_ruimte_wasmachine_726","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":700,"y":180,"wires":[[]]},{"id":"2a43d1299dfd5e48","type":"switch","z":"f0f855afd97ea0f1","name":"< of > 3W ?","property":"payload","propertyType":"msg","rules":[{"t":"lt","v":"3","vt":"num"},{"t":"gte","v":"3","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":290,"y":180,"wires":[["47b28eacd817ed0a"],["2182aa14fcd6fe65"]],"outputLabels":["Si","No"]},{"id":"47b28eacd817ed0a","type":"trigger","z":"f0f855afd97ea0f1","name":"","op1":"","op2":"Off","op1type":"nul","op2type":"str","duration":"5","extend":false,"overrideDelay":false,"units":"min","reset":"On","bytopic":"all","topic":"topic","outputs":1,"x":490,"y":180,"wires":[["51ceefbc4adb26af"]]},{"id":"2182aa14fcd6fe65","type":"change","z":"f0f855afd97ea0f1","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"On","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":500,"y":240,"wires":[["47b28eacd817ed0a"]]},{"id":"e396ce02a2df0488","type":"api-call-service","z":"f0f855afd97ea0f1","name":"Droger Off","server":"85cb4144.a30f7","version":3,"debugenabled":false,"service_domain":"switch","service":"turn_off","entityId":"switch.was_ruimte_droger_252","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":690,"y":500,"wires":[[]]},{"id":"b7fe6075aea4d17a","type":"switch","z":"f0f855afd97ea0f1","name":"< of > 3W ?","property":"payload","propertyType":"msg","rules":[{"t":"lt","v":"3","vt":"num"},{"t":"gte","v":"3","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":290,"y":500,"wires":[["096746ed0a5141d6"],["0ca7e4de2edae7be"]],"outputLabels":["Si","No"]},{"id":"096746ed0a5141d6","type":"trigger","z":"f0f855afd97ea0f1","name":"","op1":"","op2":"Off","op1type":"nul","op2type":"str","duration":"5","extend":false,"overrideDelay":false,"units":"min","reset":"On","bytopic":"all","topic":"topic","outputs":1,"x":490,"y":500,"wires":[["e396ce02a2df0488"]]},{"id":"0ca7e4de2edae7be","type":"change","z":"f0f855afd97ea0f1","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"On","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":500,"y":560,"wires":[["096746ed0a5141d6"]]},{"id":"21f99fe644ed3012","type":"comment","z":"f0f855afd97ea0f1","name":"Droger Power Monitor en auto Off","info":"","x":130,"y":320,"wires":[]},{"id":"c6312a81a82bc0fb","type":"comment","z":"f0f855afd97ea0f1","name":"Wasmachine Power Monitor en auto Off","info":"","x":155,"y":20,"wires":[]},{"id":"b09bd14a.b601d","type":"telegram bot","botname":"fibarotom_bot","usernames":"tom","chatids":"46597978","baseapiurl":"","updatemode":"polling","pollinterval":"300","usesocks":false,"sockshost":"","socksport":"6667","socksusername":"anonymous","sockspassword":"","bothost":"","botpath":"","localbotport":"8443","publicbotport":"8443","privatekey":"","certificate":"","useselfsignedcertificate":false,"sslterminated":false,"verboselogging":false},{"id":"85cb4144.a30f7","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},{"id":"16bc1ccd.414d73","type":"telegram bot","botname":"fibaropatricia_bot","usernames":"Patricia","chatids":"205329462","baseapiurl":"","updatemode":"polling","pollinterval":"300","usesocks":false,"sockshost":"","socksport":"6667","socksusername":"anonymous","sockspassword":"","bothost":"","botpath":"","localbotport":"8443","publicbotport":"8443","privatekey":"","certificate":"","useselfsignedcertificate":false,"sslterminated":false,"verboselogging":false}]

xoseperez commented 3 years ago

I see you are feeding the power monitor node with the output of a server-state-changed node, which will probably only let a message change if the power value changes, right? If that's the case I understand why you need the timer.

TBH the node was first conceived to be fed with regular (even if repetitive) values (like 0W, 0W, 0W,... every minute).

Will add this as an enhancement. In the meantime I'd suggest you to try a different approach, like feeding the data directly from the power device if possible, or timing the messages every minute.

Thank you.

dvine2000 commented 3 years ago

I understand now why it won't work like you meant to. For me is the only way to do it with a polling state node I think and check it every minute. I will test this way later on this week.

It's not complete clear in the usage tekst of node-red. Maybe ad the usage tekst: node need to be fed with regular (even if repetitive) values (like 0W, 0W, 0W,... every minute). Like you said so it's more clear in the manual of you power monitor.

Thanks for your time and looking into this and also add the enhancement. Keep up the good work

cg089 commented 2 years ago

+1 for this request. I use power monitor to monitor my solar roof. I am planing to send myself a message after a day how many watts (and how much money) I produced during the day. However, during cloudy days the roof sometimes make 0W at daytimes and continues to produce afterwards. This results in 1 (which is good) to n messages daily depending the weather.

I was wishing for an option to "Stop" after lets say "1/2/n hours of 0W readings". This would result in the planned 1 message.

Another problem that could be solved with that: my washing machine uses 0W the last couple of minutes, then again cleaning for around 15 minutes. But only when I use certain programs (white clothes at 60C). Using a different program (colored clothes at 40C) it is finished after the first time 0W. Currently I can't use the plugin to fully monitor my washing machine. An option "Stop" after "20 minutes of 0W" would perfectly monitor.

GerdRuetten commented 2 years ago

+1 from me too. My washing machine and my dryer have during working several 0 W levels for seconds time. The 0 W polling reset the power monitor, so it start always with 0.

ostat commented 2 years ago

I have created PR #17 (and #15 to a lesser extent) to assist with this scenario.

In my exp the devices I'm using messages don't appear to come in equally timed. A reading might come in at 10s, 45s, 55s then 95s for example. In this scenario the count for the stop was not as reliable as I might have liked. Waiting for 20 received messages might be 5mins it might be 10mins.

The change allows the StartBefore and StopAfter to be seconds based instead or received message count based. Setting the StopAfter period to seconds, when a message arrives instead of checking a received message count since it went in to pre-stop, it checks number of seconds since entering pre-stop. The power-monitor uses the received messages to trigger update events, this is still the case. I didn't add an internal timer that could trigger the stop, it only checks the time when an event arrives.

For example if you set StopAfter to 60 and period to Seconds. The first zero value will set the pre-stop event and record the time. If a zero value is received at 55s then another one at 90s, the stop would occur at 90s.

This still leaves the issue of what if no message is received. For that we can use a Trigger node to send a stop message after 60s of the last message.

I would be interested if someone would like to try it out.