Seemingly trivial calculation does not work

Hi all,

I measure the yield of my solar panels and created a Telegram interface. However, there is one problem I'm not able to solve...

This is the situation. The incoming MQTT message contains the total yield and I want to report the daily yield. So what I did: I created a trigger every day at 1:00 AM to set "flow.daystart" to the current total yield. This works. Then, when a new message is coming in, I try to set flow.dailyyield to the expression "msg.payload.yield - flow.daystart". However, this does not work, the flow.dailyyield is empty. If I adapt the change node to set flow.dailyyield to a numerical value (or to msg.payload.yield), there is no problem in using the value in the telegram message.

I cannot find out what is the cause. It seems that the trivial JSONata expression is not working. Do you have a clue what can be the problem?


Is msg.payload.yield a number or a string?

It was a string, but I converted it to a number in the following way:


Did you also convert flow.daystart to a number when you saved it to flow context?

Indirecty, as I set flow.daystart to the converted yield value.(For every MQTT message that comes in, I store flow.yield via above expression, and at 1:00 AM I set flow.daystart to flow.yield.)

Can we see the output debug message.

That might be part of my problem, when I debug the "changed" message, I do not see what has changed in the flow variables. This is the output:

{"topic":"domoticz/out","payload":{"Battery":255,"RSSI":12,"description":"","dtype":"General","hwid":"11","id":"00082040","idx":40,"name":"Actual PV output","nvalue":0,"stype":"kWh","power":"3535.1","yield":"7091108","unit":1},"qos":0,"retain":false,"_msgid":"d0f6a611.a93bf8"}

In this expression do you convert msg.payload.yield to a number again?

you can see the flow variable in the context window.

It is missing (opbrengst = yield, startopbrengst = daystart):

while this is the rule:

(Thank you for all the help so far!)

Does the output of the previuos node have a msg.payload.svalue2 ?

Yes (I referred to it as yield in the previous explanation). I'm certain about it, because I store the flow.yield value in the same change node:

The first depicted rule reads:


and the second:


As you can see, the flow.startopbrengst has a value, but there is no flow.dagopbrengst generated.

Simplify the rule, initially just setting it to svalue2 and make sure that works, then work up.

I asked as the data will not be written to flow if it does not exist. The other flow data you see may be previous data. Post the debug of the previous node please.

The daily trigger initializes the value to 0. When I press the inject, I see the following output:
after one incoming MQTT message, the value is gone!

The debug-output of the previous node (a switch to filter relevant messages) is:


flow.startopbrengst is not the proper JSONata expression for accessing flow context variables.

I think it should be something like:

  • $flowContext("startopbrengst") or
  • $flowContext("opbrengst")
1 Like

The flow value would only be removed if the msg.payload.svalue2 did not exisit in the payload. Is that debug output defiantly after the switch and before the change node.

Maybe you should post your flow export here.

Yes, this was the solution! I changed the expression to:


and now it works. E1cid, Jan, thanks for the help!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.