What catches my attention is in the text: âRetrieve the last stateâ.
OK?
If I understand correctly: I have a widget with a graph based on the Gazpar device that directly expresses kWh, which should not be affected, and an energy tracking based on MQTT expressing the cost and consumption converted into kWh.
I could thus integrate the subscriptionâŠ
Variable: tab « Calculated », not « Text ». In Text mode, the variable contains the phrase 5000 * 11.2 and not the result: Gladys would receive text instead of a number. Click on « Calculated » and re-enter the formula: {{triggerEvent.last_value}} * 11.2
Check the _ in last_value: the safest way is to type {{ and choose from the list.
MQTT Message: missing closing. You need {{ConversionIndexGazpar}}, with the }} at the end.
« Retrieve the last state »: thatâs just Gladysâs help. She reminds you that the variable must be created beforehand, either by « Set a variable » (your case), or by the action « Retrieve the last state ». You donât need to do anything more.
And yes, you understood correctly:
the Gazpar-based chart doesnât change, the scene just reads its value;
the energy tracking on the MQTT meter gives the consumption in kWh, the cost, and the subscription with « Display the subscription » in the « Energy Consumption » widget.
To verify: after the next GRDF reading, the MQTT index card should display a value in kWh (approximately 11 times the index in m³), and no longer « No state in history ».
Formula {{triggerEvent.last_value}} * 11.2: OK, the _ is there.
MQTT message {{ConversionIndexGazpar}}: OK.
The red line is not a Gladys error. Itâs the browserâs spell checker: it doesnât know triggerEvent. You have the same line under ConversionIndexGazpar in the MQTT message. You can ignore it.
No list after {{ in âCalculatedâ: no problem. Your manually typed formula is exactly the one the list would have inserted.
Why the consumption from two days ago didnât work:
that day, the scene was still in Text mode and the }} was missing;
a scene does not reprocess an already arrived value, it waits for the next one.
For the next steps:
Make sure to Save the scene.
At the next GRDF reading, the MQTT index card must display a value in kWh (about 11 times your index in mÂł).
This first value serves as the starting point. The consumption and cost arrive with the next reading.
Do not manually start the scene with âStartâ: without a trigger, triggerEvent.last_value is empty and your MQTT index would receive a false value.
Very well, indeed on the browser itâs the spell checker, by the way on Android phones itâs not there.
I thought that the startup would allow me to check the operation, by the way I added a message send to Telegram and when launching the scene by restarting I donât receive it, logically it being empty before the first value has no impact⊠but afterwards empty is a change of value and we lose a day, right?
No data lost, good news. When you launch the scene with « Start »:
there is no trigger event, so {{triggerEvent.last_value}} is empty;
the formula becomes * 11.2, Gladys cannot calculate it;
the scene stops abruptly at the « Set a variable » step.
Result:
no MQTT message is sent: your MQTT index received nothing, neither empty nor zero;
no day lost, the counter remains as is;
thatâs also why your Telegram message doesnât arrive: it is placed after the variable, it is never reached.
I therefore correct my previous message: « Start » does not send a false value, the scene stops before. It remains useless for testing, as it always stops at the same place.
To see for yourself, Gladys notes it in its logs:
docker logs gladys 2>&1 | grep "Set variable"
You should see Set variable: Error evaluating value at the time you clicked.
To check at the next trigger event, keep your Telegram message after the MQTT send, with both values:
Good news: this log is exactly the one expected for a « Start ». Your saved formula is therefore the correct one, the old line EventTrigger.last.value came from an earlier test.
Why spaces donât change anything:
Gladys removes all spaces before calculation;
without a trigger, {{triggerEvent.last_value}} is empty;
in both cases, the calculation receives *11.2, hence Value expected (char 1).
You can put the spaces back or leave them as they are, itâs the same.
The blue line: Gladys highlights the current step. When a step stops the scene, the interface does not receive the « step completed » signal, so the frame remains. Itâs just a display. Your way of doing it (exiting and then reopening the scene) is the right one.