Guys,
I have a flow (below) - it accepts a string in from MQTT, runs it through a change node and outputs to the dashboard to tell me the state of incoming values.
What it does not do is to telll me when state transitions occur and what the transition was - it is at this stage purely an informational display on the dashboard.
Last week i made a request for some help with the next stage of development to enable me to identify and capture the transitions so they can be recorded and later analyzed - so i can say at (say) 1:30PM Solar On, 3:30PM Solar Off etc
Based on the responses from all the senior guys to my cry for help - i chose to follow a path that Andrei suggested in this thread - Advice please on best way to attack this
I have been slowly building that up and believe that i have that almost ready to implement.
However before i get to that i have an issue with initialisation of my data after a restart - here is the flow
[{"id":"32abd967.0a4c56","type":"mqtt in","z":"a78930fe.ed232","name":"Picaxe Pins Output Status","topic":"PicaxeOutputStatus","qos":"2","broker":"389dd264.7716de","x":150,"y":1540,"wires":[["f828a955.f5f338","86972491.f793a8","2f3e3321.e5e1bc"]]},{"id":"f828a955.f5f338","type":"debug","z":"a78930fe.ed232","name":"PicaxeStringDebug","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":430,"y":1520,"wires":[]},{"id":"d1b4a842.c505c8","type":"ui_text","z":"a78930fe.ed232","group":"b7f64022.ddf0d","order":1,"width":0,"height":0,"name":"Status Update","label":"System Status","format":"{{msg.payload}}","layout":"col-center","x":740,"y":1560,"wires":[]},{"id":"86972491.f793a8","type":"change","z":"a78930fe.ed232","name":"Parse Picaxe Outputs and Report","rules":[{"t":"change","p":"payload","pt":"msg","from":"128.00","fromt":"str","to":"OutPut Status: Overheat CP Off","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"144.00","fromt":"str","to":"Circ Pump on - no heat","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"160.00","fromt":"str","to":"Overheat ! CP Off - Solar On","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"176.00","fromt":"str","to":"Solar On - CP On","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"192.00","fromt":"str","to":"CP off - Boiler on","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"208.00","fromt":"str","to":"Boiler on - CP on","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":480,"y":1560,"wires":[["d1b4a842.c505c8"]]},{"id":"bd9d6b84.f540a8","type":"function","z":"a78930fe.ed232","name":"TestFunction","func":"//This function will only get output on the change of\n//Pins value from Picaxe/Arduino\n\n//We need to capture the current state from the flow variable\n//Then update that with the new values\n\n//Then we need to perform calculations to work out what\n//has changed with the transition\nvar p = flow.get('PreviousPicaxePinState') || 0;\n\n//Read Current Value of Variable If Blank then set to 0\nvar c = flow.get('CurrentPicaxePinState') || 0;\n\n//Save the Previous value so it can be used later\nflow.set('PreviousPicaxePinState', c);\n\n//Assign incoming value to variable\nvar n = msg.payload;\n\n//Update the Flow varaible\nflow.set('CurrentPicaxePinState', n);\n\nvar n = (c.slice(0, 3) + (p.slice(0, 3)));\nmsg.payload = n;\nreturn msg;","outputs":2,"noerr":0,"x":410,"y":1640,"wires":[["3072377d.fda008","7af13880.aa14e8"],[]]},{"id":"3072377d.fda008","type":"debug","z":"a78930fe.ed232","name":"TestFunctionVariable","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":760,"y":1640,"wires":[]},{"id":"2f3e3321.e5e1bc","type":"rbe","z":"a78930fe.ed232","name":"TestForPinStateChange","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":450,"y":1600,"wires":[["8e7a7b75.f17478","bd9d6b84.f540a8"]]},{"id":"8e7a7b75.f17478","type":"debug","z":"a78930fe.ed232","name":"RBETestDebug","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":740,"y":1600,"wires":[]},{"id":"7af13880.aa14e8","type":"link out","z":"a78930fe.ed232","name":"Out to Status and Action","links":["28448ec9.40c042"],"x":555,"y":1680,"wires":[]},{"id":"389dd264.7716de","type":"mqtt-broker","z":"a78930fe.ed232","broker":"localhost","port":"1883","clientid":"Node-Red","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"b7f64022.ddf0d","type":"ui_group","z":"","name":"Control Status","tab":"c9d53e06.a95c8","order":2,"disp":true,"width":"6"},{"id":"c9d53e06.a95c8","type":"ui_tab","z":"","name":"CURTIN house main page","icon":"dashboard","order":1}]
Lets say that the MQTT incoming data is 176 - i do a reload of NR and the first data (for example) it gets in is 128 my variable that i want to pass along to Andrei's function should be 176128 but what happens is that the first value is initialised as the first incoming data and the 2nd run through gives me the same so i end up with 176176 - which is not a valid action i.e. nothing has changed - at the moment whilst i am testing this i have written some dummy values in Andreis function for each of these cases (128128, 144144 etc etc) - but i am looking for a better way to handle it.
Would i be better off writing the value each time i take a reading into a text file that could then be read back for the first run ? I am running this on a PC/VM so do not have any write issues with media etc.
Any input greatly appreciated
(First time pasting a flow - hopefully got that one right)
regards
Craig