I am sure this is a really quick question, I have just confused myself
I have a value from MQTT that I want to store at 23:55pm every night. It is the total kWh that IoT device has logged for the day (so the interval is daily).
I do loads of MQTT >Some transformation> Influx2.0DB logging on these devices. Where I have confused myself is I just need to store this value once a day at 23:55pm.
Typically all I would do is setup an inject node with the correct schedule but you cant connect the inject node to an MQTT output node to trigger the read at that time and then to other flow to store.
So a little embarrassed to ask if someone could just clarify how I would set this up on a flow. The end result would be:
Depends on how you write your code and what you want to achieve.
// Example of writing a new value to a global variable (overwites old value)
// This is the most common way it is used
let new_value_from_mqtt = msg.payload; //This would come from your MQTT-In node
global.set("name", new_value_from_mqtt);
// Example of adding a new value to a global variable (adds to old value)
let new_value_from_mqtt = msg.payload; //This would come from your MQTT-In node
let current_value = global.get("name");
let updated_value = new_value_from_mqtt + current_value;
global.set("name", updated_value);
Thank you @zenofmud -
So I need to figure out what the device is actually doing right now in terms of update. Let me explain.
The device is a Sonoff Switch, it show on the its own dashboard the real time values and its connected to a MQTT broker via its settings.
On the device I can see the right values updated in real time. In MQTT I can see value but dont see the right values. What does this mean:
For example the Total Energy Today gets incremented every time the boiler heats. In MQTT currently it is showing a value of 2.35 kWh but on the device its showing 4.23 kWh. Network is up, MQTT is up so I need to figure out how the Sonoff is updating to MQTT - I use many Sonoff devices and they update MQTT when there is a change so this does seem weird.
Back to your question:
Basically what I am trying to do is store the value from the device > MQTT > Influx DB 2.x so that i can then use a front end like Grafana to plot the electricity usage. On the query side I have the query working out the cost per kWH etc. I was wanting to use the "TodayEnergyUsage" value to provide me with a view of cost per day and then extrapulate over a week, month.
The "TodayEnergyUsage" value is updated constantly, so when the boiler comes on and uses energy it increments the "TodayEnergyUsage". The reason I was thinking of storing it once only at 23:55pm was to get the total usage once for the day at that time and then use the "real time / last reading" for current value.
You can poll the tasmota device every 24hr to retrieve the power usage.
Sonoff Pow (and any device with sensors) status can be requested manually with cmnd/tasmota/status 8. Additionally, Tasmota periodically sends telemetry every TelePeriod, which defaults to 300 seconds (5 minutes).
I am not sure its a solution but rather a way to to get the values to appear so needs more investigation.
Basically if I reboot the Tasmota device it updates the values in MQTT. If the device just runs its not updating the values as they are updated on the device dashboard.
Need to figure out why its not doing it dynamically i.e. as value is updated on Tasmota that is pushed into MQTT
Great tip! I have about 23 different devices between PowR2 and Pow3 devices, never checked the time zone3. Of course the time zone is wrong as its set by default to UTC, updated it now to the right time zone - thank you!
You can also change the update interval using the teleperiod command at the console - by default it is 300 seconds - hence 5 minutes - you can change it on the tasmota console (permanently) using