Colin,
Here is what i am trying to do
I have a Tasmota POWr2 that controls the power to my pool pump.
The Tasmota firmware has been setup to talk to my MQTT Broker and to broadcast its stats every minute (Teleperiod 60)
Essentially i grab the incoming data and look for either ON or OFF that the Tasmota transmits - i then want to keep a running counter of the on time for the day and a 2nd counter for the week
I know there are lots of ways to do this - but i thought using the DSM nodes would give me some more practise with them.
So i have taken his operating time example here
And used that.
I am attemtping to keep two counters - a daily and a weekly.
The only change i have made to his node is to change the interval from 1 (second) to 60 (minute) as i did not need the display updated that often
Ultimately i will need to store these values across restarts and to then see the DSM node with that as well - but that is further down the track.
The main problem i have now is
-
If i reset the Daily node (which i do at midnight as an example) as soon as it sees the next off (every minute) it then seeds the node with a huge negative value and starts the timer again - rather than just ignoring it until the next start is received.
-
As an extension of that if it Stop the node in the middle of the day (low solar output) it continues to count everytime it sees a stop arrive - rather than ignoring them until restarted
Any ideas on this ?/ I have tried to message @cflurin but it appears he has not been active for quite a while.
You can see the behaviour i have described just using his example nodes rather than my flow - but i also post my flow here for completenes
regards
Craig
[{"id":"e459f4e.76f2508","type":"mqtt in","z":"bc5cdb17.6d6b48","name":"MQTT from Pool Pump","topic":"tele/Tasmota_Pool_Pump_Controller/STATE","qos":"2","datatype":"auto","broker":"8c5be0a1.64904","x":160,"y":240,"wires":[["256cc97b.87a5e6"]]},{"id":"967f9355.0ad1c","type":"debug","z":"bc5cdb17.6d6b48","name":"test","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":810,"y":160,"wires":[]},{"id":"256cc97b.87a5e6","type":"json","z":"bc5cdb17.6d6b48","name":"Turn into an object","property":"payload","action":"","pretty":false,"x":150,"y":300,"wires":[["6328b52c.3006ec","1b492848.1d6328"]]},{"id":"d38d90c1.69994","type":"switch","z":"bc5cdb17.6d6b48","name":"Test on message payload and switch","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"OFF","vt":"str"},{"t":"eq","v":"ON","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":870,"y":240,"wires":[["12bc9881.faabb7","b6bde247.29e28"],["12bc9881.faabb7","e54e64c1.508308"]]},{"id":"6328b52c.3006ec","type":"change","z":"bc5cdb17.6d6b48","name":"Move the Power State to Message Payload","rules":[{"t":"move","p":"payload.POWER","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":490,"y":280,"wires":[["d38d90c1.69994","967f9355.0ad1c"]]},{"id":"74e2c789.1a9188","type":"comment","z":"bc5cdb17.6d6b48","name":"Capture State of Pool Pump and increment Runtime","info":"","x":250,"y":180,"wires":[]},{"id":"5fd41a90.dcf374","type":"inject","z":"bc5cdb17.6d6b48","name":"Reset Daily Run Counter for Pool Pump","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"01 00 * * *","once":false,"onceDelay":0.1,"topic":"reset","payload":"","payloadType":"date","x":200,"y":580,"wires":[["c299f7f9.b4a088"]]},{"id":"bdc3372e.2e3c38","type":"inject","z":"bc5cdb17.6d6b48","name":"Reset Weekly Run Counter for Pool Pump","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"01 00 * * 1","once":false,"onceDelay":0.1,"topic":"reset","payload":"","payloadType":"date","x":210,"y":620,"wires":[["bd7409ad.071848"]]},{"id":"c40cc04c.732ce","type":"comment","z":"bc5cdb17.6d6b48","name":"Reset Daily and Weekly Counters","info":"","x":170,"y":540,"wires":[]},{"id":"12bc9881.faabb7","type":"ui_text","z":"bc5cdb17.6d6b48","group":"dea21ffd.1483","order":0,"width":0,"height":0,"name":"Pool Pump Status","label":"Pump On/Off Status","format":"{{msg.payload}}","layout":"col-center","x":1290,"y":280,"wires":[]},{"id":"1b492848.1d6328","type":"debug","z":"bc5cdb17.6d6b48","name":"Object Output","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":140,"y":360,"wires":[]},{"id":"e54e64c1.508308","type":"change","z":"bc5cdb17.6d6b48","name":"Start the Timer","rules":[{"t":"set","p":"payload","pt":"msg","to":"","tot":"date"},{"t":"set","p":"topic","pt":"msg","to":"on","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":780,"y":320,"wires":[["c299f7f9.b4a088","bd7409ad.071848"]]},{"id":"c299f7f9.b4a088","type":"dsm","z":"bc5cdb17.6d6b48","name":"Daily operating time","sm_config":"{\n \"currentState\": \"stopped\",\n \"states\": {\n \"stopped\": {\n \"on\": \"started\"\n },\n \"started\": {\n \"inc\": \"counting\",\n \"off\": \"stopped\"\n },\n \"counting\": {\n \"inc\": \"counting\",\n \"off\": \"stopped\"\n }\n },\n \"data\": {\n \"prev_time\": null,\n \"time\": 0,\n \"seconds\": 0,\n \"interval\": 60,\n \"interval_output\": true,\n \"hms_format\": true\n },\n \"methods\": {\n \"init\": [\n \"sm.calc_time = function() {\",\n \" var now = Date.now();\",\n \" sm.data.time += now - sm.data.prev_time;\",\n \" sm.data.prev_time = now;\",\n \" sm.data.seconds = Math.round(sm.data.time / 1000);\",\n \"};\",\n \"sm.sec2hhmmss = function(sec) {\",\n \"var t = {};\",\n \"t.h = pad(Math.floor(sec / 3600));\",\n \"sec %= 3600;\",\n \"t.m = pad(Math.floor(sec / 60));\",\n \"t.s = pad(sec % 60);\",\n \"return t.h+':'+t.m+':'+t.s;\",\n \"};\"\n ],\n \"on\": [\n \"if (sm.currentState === 'started') {\",\n \" sm.data.prev_time = Date.now();\",\n \" resume('inc', msg);\",\n \"}\",\n \"output = false;\"\n ],\n \"inc\": [\n \"timeout.interval = setTimeout(function() {\",\n \" sm.calc_time();\",\n \" msg.data = sm.data;\",\n \" if (sm.data.interval_output) {\",\n \" msg.payload = sm.data.hms_format ? sm.sec2hhmmss(sm.data.seconds): sm.data.seconds;\",\n \" node.send(msg);\",\n \" }\",\n \" resume('inc', msg);\",\n \"}, sm.data.interval*1000);\",\n \"output = false;\"\n ],\n \"off\": [\n \"clearTimeout(timeout.interval);\",\n \"sm.calc_time();\",\n \"msg.payload = sm.data.hms_format ? sm.sec2hhmmss(sm.data.seconds): sm.data.seconds;\"\n ],\n \"reset\": [\n \"sm.data.time = 0;\",\n \"sm.data.seconds = 0;\"\n ],\n \"status\": {\n \"fill\": {\n \"get\": \"sm.currentState === 'counting' ? 'green' : 'grey';\"\n },\n \"shape\": \"dot\",\n \"text\": {\n \"get\": \"'time ' + (sm.data.hms_format ? sm.sec2hhmmss(sm.data.seconds): sm.data.seconds);\"\n }\n }\n }\n}\n","x":900,"y":380,"wires":[["57540f79.5d4c4"]]},{"id":"57540f79.5d4c4","type":"ui_text","z":"bc5cdb17.6d6b48","group":"dea21ffd.1483","order":0,"width":0,"height":0,"name":"Todays Running Time","label":"Todays Runtime","format":"{{msg.payload}}","layout":"row-spread","x":900,"y":440,"wires":[]},{"id":"b6bde247.29e28","type":"change","z":"bc5cdb17.6d6b48","name":"Stop the TImer","rules":[{"t":"set","p":"topic","pt":"msg","to":"off","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"","tot":"date"}],"action":"","property":"","from":"","to":"","reg":false,"x":1000,"y":320,"wires":[["c299f7f9.b4a088","bd7409ad.071848","b80234e8.5138b8"]]},{"id":"ddab9878.a65f98","type":"inject","z":"bc5cdb17.6d6b48","name":"reset","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"reset","payload":"","payloadType":"date","x":630,"y":380,"wires":[["c299f7f9.b4a088"]]},{"id":"bd7409ad.071848","type":"dsm","z":"bc5cdb17.6d6b48","name":"Weekly operating time","sm_config":"{\n \"currentState\": \"stopped\",\n \"states\": {\n \"stopped\": {\n \"on\": \"started\"\n },\n \"started\": {\n \"inc\": \"counting\",\n \"off\": \"stopped\"\n },\n \"counting\": {\n \"inc\": \"counting\",\n \"off\": \"stopped\"\n }\n },\n \"data\": {\n \"prev_time\": null,\n \"time\": 0,\n \"seconds\": 0,\n \"interval\": 60,\n \"interval_output\": true,\n \"hms_format\": true\n },\n \"methods\": {\n \"init\": [\n \"sm.calc_time = function() {\",\n \" var now = Date.now();\",\n \" sm.data.time += now - sm.data.prev_time;\",\n \" sm.data.prev_time = now;\",\n \" sm.data.seconds = Math.round(sm.data.time / 1000);\",\n \"};\",\n \"sm.sec2hhmmss = function(sec) {\",\n \"var t = {};\",\n \"t.h = pad(Math.floor(sec / 3600));\",\n \"sec %= 3600;\",\n \"t.m = pad(Math.floor(sec / 60));\",\n \"t.s = pad(sec % 60);\",\n \"return t.h+':'+t.m+':'+t.s;\",\n \"};\"\n ],\n \"on\": [\n \"if (sm.currentState === 'started') {\",\n \" sm.data.prev_time = Date.now();\",\n \" resume('inc', msg);\",\n \"}\",\n \"output = false;\"\n ],\n \"inc\": [\n \"timeout.interval = setTimeout(function() {\",\n \" sm.calc_time();\",\n \" msg.data = sm.data;\",\n \" if (sm.data.interval_output) {\",\n \" msg.payload = sm.data.hms_format ? sm.sec2hhmmss(sm.data.seconds): sm.data.seconds;\",\n \" node.send(msg);\",\n \" }\",\n \" resume('inc', msg);\",\n \"}, sm.data.interval*1000);\",\n \"output = false;\"\n ],\n \"off\": [\n \"clearTimeout(timeout.interval);\",\n \"sm.calc_time();\",\n \"msg.payload = sm.data.hms_format ? sm.sec2hhmmss(sm.data.seconds): sm.data.seconds;\"\n ],\n \"reset\": [\n \"sm.data.time = 0;\",\n \"sm.data.seconds = 0;\"\n ],\n \"status\": {\n \"fill\": {\n \"get\": \"sm.currentState === 'counting' ? 'green' : 'grey';\"\n },\n \"shape\": \"dot\",\n \"text\": {\n \"get\": \"'time ' + (sm.data.hms_format ? sm.sec2hhmmss(sm.data.seconds): sm.data.seconds);\"\n }\n }\n }\n}\n","x":1170,"y":380,"wires":[["7172c623.e95c98"]]},{"id":"7172c623.e95c98","type":"ui_text","z":"bc5cdb17.6d6b48","group":"dea21ffd.1483","order":0,"width":0,"height":0,"name":"Weekly Running Time","label":"Weekly Runtime","format":"{{msg.payload}}","layout":"row-spread","x":1160,"y":440,"wires":[]},{"id":"b80234e8.5138b8","type":"debug","z":"bc5cdb17.6d6b48","name":"Output of Off","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1250,"y":320,"wires":[]},{"id":"8c5be0a1.64904","type":"mqtt-broker","z":"","name":"MQTT-On-Dev","broker":"172.16.100.36","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"dea21ffd.1483","type":"ui_group","z":"","name":"Pump Status","tab":"dd590918.d334c8","order":1,"disp":true,"width":"6","collapse":false},{"id":"dd590918.d334c8","type":"ui_tab","z":"","name":"Pool Control","icon":"dashboard","disabled":false,"hidden":false}]