Read latest power level when changed within the same piston


#1

I have a piston which turns on a load, as a result an energy monitors value will change. I want to store the new energy value, once the load has turned on. However, I seem to be storing the value before the load was turned on by the piston. I suspect this is because all values are cached when a piston starts?

Is this assumption correct? And can I read the current value? I’ve tried running a poll & refresh command on the energy monitor device, but that does not help.

I don’t have a simple example to show, it’s part of a large complex piston which handles an IR controlled lighting controller via a logitech harmony. A virtual dimmer sets the scenes via the harmony. I want to store the power for each, so they can be compared when the controller is operated manually, and then set the corresponding scene on the virtual switch.


#2

Are the energy values the trigger?

It would good to understand if the piston is polling, etc.


#3

No, the problem is that the when the device turns on the energy level is 0. That takes time to update in Huibitat. It will not be instantly. so, you will want to put a wait in between the switch turning on and when the value is pulled for the energy level.


#4

I’ve tried with a 10 second wait and the power level is still from level 0, even though on the HE dash you can see it’s increased.

The piston is not polling as such. It does trigger if the energy level goes above or below a level to turn the virtual dimmer on/off.
The part not working is a trigger:-
-the virtual dimmer changes level (trigger)
-commands are set via harmony to change the scene on the IR lighting controller
-scene changes and power usage changes
-piston waits 2 secs then reads power usage from the power monitor (fibraro single switch)
At this point the power level is still the previous level, although it is now showing higher on the HE dashboard

I also tried calling another piston to report the owner level and that too reports the previous level


#5

Please post the piston (green) and full logs.

Instructions:


#6

This is the full (work in progress) piston. Futronix pdu is a fibaro switch, its always on & is only used to read the power used by the futronix p800 lighting controller. Kitchen lights is a virtual dimmer - its levels 1-20 are used to correspond to the scenes on the p800
I’ve coded round the issue using the final if statement of the piston, however, I’m still curious about the power level read in the main body after a scene change has been sent (prefixed with ORIG in the log)

31/01/2023, 19:36:18 +743ms
+3ms ╔Received event [Futronix PDU].power = 125.7 with a delay of 27ms, canQueue: true, calledMyself: false
+14ms ║RunTime initialize > 14 LockT > 1ms > r9T > 2ms > pistonT > 1ms (first state access 8 m:11 4 10)
+18ms ║Runtime (16054 bytes) initialized in 2ms (v0.3.114.20230113_HE)
+20ms ║╔Execution stage started
+24ms ║║Comparison (enum) on changes_to (string) off = false (0ms)
+25ms ║║Condition #2 evaluated false (2ms)
+25ms ║║Condition group #1 evaluated false (condition did not change) (4ms)
+28ms ║║Comparison (integer) 1 changes = false (0ms)
+28ms ║║Condition #9 evaluated false (2ms)
+30ms ║║Comparison (enum) on changes_to (string) on = false (0ms)
+32ms ║║Condition #10 evaluated false (3ms)
+33ms ║║Condition group #8 evaluated false (condition changed) (7ms)
+36ms ║║Comparison (decimal) 125.7 drops_below (decimal) 10.0 = false (1ms)
+37ms ║║Condition #46 evaluated false (3ms)
+38ms ║║Condition group #45 evaluated false (condition did not change) (3ms)
+41ms ║║Comparison (decimal) 125.7 rises_above (decimal) 10.0 = true (0ms)
+42ms ║║Condition #51 evaluated true (4ms)
+44ms ║║Condition group #50 evaluated true (condition changed) (5ms)
+46ms ║║Comparison (enum) on is (string) off = false (1ms)
+47ms ║║Condition #53 evaluated false (3ms)
+48ms ║║Condition group #52 evaluated false (condition did not change) (3ms)
+50ms ║║Comparison (decimal) 125.7 changes = true (0ms)
+52ms ║║Condition #58 evaluated true (3ms)
+53ms ║║Condition group #57 evaluated true (condition changed) (5ms)
+55ms ║║Calculating (integer)10 * (integer)1000 >> (integer)10000
+56ms ║║Calculating (datetime)1675193771005 + (integer)10000 >> (datetime)1675193781005
+60ms ║║Comparison (datetime) 1675193781005 is_greater_than (datetime) 1675193778801 = true (1ms)
+61ms ║║Condition #60 evaluated true (8ms)
+62ms ║║Condition group #59 evaluated true (condition changed) (9ms)
+68ms ║║Executed virtual command setVariable (2ms)
+72ms ║║Calculating (string)SCN + (string)0 >> (string)SCN 0
+73ms ║║Calculating (string)SCN 0 + (string) PWR >> (string)SCN 0 PWR
+75ms ║║Calculating (string)SCN 0 PWR + (string)125.7 >> (string)SCN 0 PWR 125.7
+77ms ║║SCN 0 PWR 125.7
+79ms ║║Executed virtual command log (2ms)
+82ms ║╚Execution stage complete. (63ms)
+86ms ╚Event processed successfully (83ms)
31/01/2023, 19:36:10 +940ms
+4ms ╔Received event [Home].time = 1675193770916 with a delay of 24ms, canQueue: true, calledMyself: false
+13ms ║RunTime initialize > 13 LockT > 0ms > r9T > 2ms > pistonT > 1ms (first state access 7 m:11 4 9)
+17ms ║Runtime (16046 bytes) initialized in 2ms (v0.3.114.20230113_HE)
+23ms ║╔Execution stage started
+60ms ║║Executed device command [Harmony Hub-Ftrnx scn01].off() (29ms)
+64ms ║║Executed virtual command [Harmony Hub-Ftrnx scn01].setVariable (1ms)
+69ms ║║Executed virtual command [Harmony Hub-Ftrnx scn01].setVariable (1ms)
+160ms ║║Executed device command [Futronix PDU].refresh() (87ms)
+166ms ║║Executed virtual command [Futronix PDU].setVariable (3ms)
+171ms ║║Calculating (string)Orig SCN + (string)0 >> (string)Orig SCN 0
+172ms ║║Calculating (string)Orig SCN 0 + (string) PWR >> (string)Orig SCN 0 PWR
+174ms ║║Calculating (string)Orig SCN 0 PWR + (string)3.2 >> (string)Orig SCN 0 PWR 3.2
+177ms ║║Orig SCN 0 PWR 3.2
+179ms ║║Executed virtual command [Futronix PDU].log (2ms)
+182ms ║║Comparison (integer) 1 is_equal_to (integer) 100 = false (1ms)
+183ms ║║Condition #34 evaluated false (3ms)
+184ms ║║Condition group #33 evaluated false (condition did not change) (4ms)
+186ms ║║Comparison (boolean) true is_not (boolean) true = false (1ms)
+187ms ║║Condition #42 evaluated false (3ms)
+188ms ║║Condition group #41 evaluated false (condition did not change) (3ms)
+191ms ║║Comparison (decimal) 3.2 drops_below (decimal) 10.0 = false (0ms)
+192ms ║║Condition #46 evaluated false (3ms)
+192ms ║║Condition group #45 evaluated false (condition did not change) (4ms)
+195ms ║║Comparison (decimal) 3.2 rises_above (decimal) 10.0 = false (1ms)
+196ms ║║Condition #51 evaluated false (3ms)
+197ms ║║Condition group #50 evaluated false (condition did not change) (3ms)
+199ms ║║Comparison (decimal) 3.2 changes = false (0ms)
+201ms ║║Condition #58 evaluated false (3ms)
+202ms ║║Condition group #57 evaluated false (condition changed) (5ms)
+204ms ║╚Execution stage complete. (182ms)
+207ms ╚Event processed successfully (204ms)
31/01/2023, 19:36:08 +651ms
+2ms ╔Received event [Kitchen Lights].switch = on with a delay of 43ms, canQueue: true, calledMyself: false
+13ms ║RunTime initialize > 12 LockT > 1ms > r9T > 2ms > pistonT > 1ms (first state access 6 m:9 3 9)
+18ms ║Runtime (15979 bytes) initialized in 2ms (v0.3.114.20230113_HE)
+20ms ║╔Execution stage started
+24ms ║║Comparison (enum) on changes_to (string) off = false (1ms)
+25ms ║║Condition #2 evaluated false (3ms)
+26ms ║║Condition group #1 evaluated false (condition did not change) (3ms)
+29ms ║║Comparison (integer) 1 changes = false (0ms)
+29ms ║║Condition #9 evaluated false (2ms)
+32ms ║║Comparison (enum) on changes_to (string) on = true (0ms)
+33ms ║║Condition #10 evaluated true (3ms)
+35ms ║║Condition group #8 evaluated true (condition changed) (8ms)
+40ms ║║Executed virtual command setVariable (2ms)
+43ms ║║Calculating (integer)1 - (integer)1 >> (integer)0
+46ms ║║Executed virtual command setVariable (1ms)
+48ms ║║Calculating (integer)2 * (integer)1000 >> (integer)2000
+50ms ║║Calculating (datetime)1675191409206 + (integer)2000 >> (datetime)1675191411206
+53ms ║║Comparison (datetime) 1675191411206 is_less_than (datetime) 1675193768702 = true (2ms)