Follow-up: TotalEnergies contracts

I have Gladys+, so no worries 


Next:

Then :slight_smile:

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


Hello @JPPUYB,

Almost there, just two corrections:

  1. 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.
  2. 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 ».

Today (actually, two days ago) I had a consumption but no effect. Also, I noticed that :slight_smile:

It’s stuck at this second step. It seems the function is not accepted
 There is no list offered 


End of MQTT message :vu.

Your opinion, please.

Hello @JPPUYB,

Your scene is good now:

  • “Calculated” tab: OK.
  • 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:

  1. Make sure to Save the scene.
  2. At the next GRDF reading, the MQTT index card must display a value in kWh (about 11 times your index in mÂł).
  3. 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.

Keep me posted after the next reading.

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?

Out of curiosity, what language is behind it?

I posted a link to this thread on :slight_ **External Integration - GRDF GAZPAR**smile:

Thanks for your patience :grinning_face_with_smiling_eyes:

Hello @JPPUYB,

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:

Gazpar : {{triggerEvent.last_value}} m³ → {{ConversionIndexGazpar}} kWh

If you receive it, the whole chain works.

The language behind:

  • Gladys is written in JavaScript (Node.js for the server, Preact for the interface);
  • the {{ }} are Handlebars templates: they replace a name with its value;
  • the « Calculated » mode then passes the text to mathjs, limited to calculation functions (+, −, ×, Ă·, rounding, min, max
);
  • the TotalEnergies integration is also in JavaScript (Node.js).

Thank you for the link to the GRDF Gazpar topic, it will help the next ones :slightly_smiling_face:

Keep me posted after the next trigger event.

Two things: on Android the step remained frozen with a blue outline and a blue bar at the top on Windows


Found: Set variable: Error evaluating value: EventTrigger.last.value * 11.2
Followed by: Undefined symbol EventTrigger

OK as soon as it moves
 See you soon.

Hello @JPPUYB,

Good idea to check the logs, it teaches us something.

Gladys writes the formula as it is recorded, before replacing the {{ }}. However, your line shows:

EventTrigger.last.value * 11.2

  • no {{ }};
  • EventTrigger instead of triggerEvent;
  • last.value instead of last_value.

That’s why you have Undefined symbol EventTrigger: the calculation is looking for a number called « EventTrigger ».

With the formula from your screenshot, a « Start » would rather give:

Set variable: Error evaluating value: {{triggerEvent.last_value}} * 11.2

Value expected (char 1)

Two possibilities:

  • this line comes from an older attempt (before your correction);
  • or the recorded formula is not the one you see on screen (for example a modification made on the phone and not saved).

To find out, display all attempts with their time:

docker logs -t gladys 2>&1 | grep -A1 “Set variable”

The last line should correspond to your last click on « Start ».

Next:

  • reload the scene page (F5);
  • check that the « Calculated » field contains {{triggerEvent.last_value}} * 11.2;
  • if it doesn’t, correct it, then Save.

For the step « frozen » in blue: reload the page (F5). If it remains stuck, send me a screenshot.

Keep me posted at the next reading.

I’m retaking the last log because I actually did a test, so replay:

scene.actions.js:556 (Object.variable.set) Set variable: Error evaluating value: {{triggerEvent.last_value}} * 11.2
scene.actions.js:557 (Object.variable.set) SyntaxError: Value expected (char 1)

I removed the spaces around *:

scene.actions.js:556 (Object.variable.set) Set variable: Error evaluating value: {{triggerEvent.last_value}}*11.2
scene.actions.js:557 (Object.variable.set) SyntaxError: Value expected (char 1)

So same punishment


Other observation: (F5) no effect

As a workaround, since I’m on the scene editing page and I save then Start: blue line:

To refresh the screen, I go back to the widget, start. Then I re-edit the scene: no blue line.

Hello @JPPUYB,

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.

I have reported this display issue to the Gladys developers: Scene editor: step stays highlighted when an action aborts the scene · Issue #3456 · GladysAssistant/Gladys · GitHub

If you want to test the « Calculated » mode without waiting for GRDF, create a separate test scene:

  1. « Set a variable » Test, « Calculated » tab: 5000*11.2;
  2. a Telegram message: Test: {{Test}};
  3. « Start ».

You should receive Test: 56000. Do not put any MQTT send in this test scene: your index would receive a false value.

For the real scene, there is nothing more to do. We wait for the next GRDF reading.

Keep me informed.