Persistent Variable
Moderators: grovkillen, Stuntteam, TD-er
-
- Normal user
- Posts: 57
- Joined: 28 Sep 2020, 13:58
Persistent Variable
Hi
I've made an Espresso temperature controller and need to be able to store the set temperature as a variable that survives power loss. My plan is to use a custom dashboard.esp to set the temperature with a simple web interface.
I can't see a way of storing a persistent variable.
Please help!
Tony
I've made an Espresso temperature controller and need to be able to store the set temperature as a variable that survives power loss. My plan is to use a custom dashboard.esp to set the temperature with a simple web interface.
I can't see a way of storing a persistent variable.
Please help!
Tony
Re: Persistent Variable
There is no official way of storing a setting, other than having that in a Config page for a plugin, but there is an accepted work-around: You can use the 'Regulator - Level control' (P021) to set a value using the 'setlevel,(value)' command. It has an option to save the value immediately (not recommended) or you can save all settings using a 'save' command at a convenient time (should be used sparingly, to avoid damaging the Flash memory, as the max number of flash-writes are limited).
Some safety is already built into the plugin so it won't save if the value hasn't changed, but avoiding automatically saving that value every time it changes is strongly advised. You can set a flag once the value is changed, and check that flag, say once per 30 minutes, and only save if really needed.
Hm, that's actually a nice feature request, adding a configurable "auto-save after x minutes when changed" option
I'll put that on my TODO list
Some safety is already built into the plugin so it won't save if the value hasn't changed, but avoiding automatically saving that value every time it changes is strongly advised. You can set a flag once the value is changed, and check that flag, say once per 30 minutes, and only save if really needed.
Hm, that's actually a nice feature request, adding a configurable "auto-save after x minutes when changed" option
I'll put that on my TODO list
/Ton (PayPal.me)
-
- Normal user
- Posts: 57
- Joined: 28 Sep 2020, 13:58
Re: Persistent Variable
Thanks for that. What would the URL look like to set the Set Level?
I tried /control?cmd=config,3,Set_Temp,SetLevel,89
...but I seem to be barking up the wrong tree.
Help appreciated.
Tony
I tried /control?cmd=config,3,Set_Temp,SetLevel,89
...but I seem to be barking up the wrong tree.
Help appreciated.
Tony
Re: Persistent Variable
That url looks like you combined 2 commands, but setlevel is a separate command, specific to the Level plugin.
NB: When testing a command from the Tools page of ESPEasy, you can see the url in your browsers address bar
NB: When testing a command from the Tools page of ESPEasy, you can see the url in your browsers address bar
/Ton (PayPal.me)
Re: Persistent Variable
It was me that was mixed up, sorry, I mistakenly assumed the plugin used a regular command, but it needs to use the config command like: 'config,task,(taskname),setlevel,(value)',
so for your example, it should look like:
The second argument should literally be 'task', as the original intention was that using the 'config' command, all type of settings, like Tasks, Controllers, Notifications, etc., could be changed, but that hasn't been continued (yet).
so for your example, it should look like:
Code: Select all
config,task,Set_Temp,SetLevel,89
/Ton (PayPal.me)
-
- Normal user
- Posts: 57
- Joined: 28 Sep 2020, 13:58
Re: Persistent Variable
Thanks, that works. But then in the Rules, [Set_Temp#GetLevel] does not return a value.
Re: Persistent Variable
How do you use it in the rules?
See: https://espeasy.readthedocs.io/en/lates ... -available
I assume your taskname is Set_temp ?
This should even work when called from command field on the tools page.
See: https://espeasy.readthedocs.io/en/lates ... -available
I assume your taskname is Set_temp ?
This should even work when called from command field on the tools page.
Code: Select all
logEntry,"The level is: [Set_temp #GetLevel]"
-
- Normal user
- Posts: 57
- Joined: 28 Sep 2020, 13:58
Re: Persistent Variable
That's what I thought, but no result.
From rules:
On Rules#Timer=1 do
// Target temp
let,1,[Set_Temp#GetLevel]
Log:
4509072: EVENT: Rules#Timer=1,1
4509095: ACT : let,1,Y
4509100: Calculate: Unknown token input: Y = 0
4509106: ACT : let,2,0-33
4509115: ACT : let,3,0-15
4509124: ACT : let,4,0-7
4509133: ACT : let,5,0-2
4509141: ACT : let,6,0-1
Sorry about this, I'm probably doing something silly!
From rules:
On Rules#Timer=1 do
// Target temp
let,1,[Set_Temp#GetLevel]
Log:
4509072: EVENT: Rules#Timer=1,1
4509095: ACT : let,1,Y
4509100: Calculate: Unknown token input: Y = 0
4509106: ACT : let,2,0-33
4509115: ACT : let,3,0-15
4509124: ACT : let,4,0-7
4509133: ACT : let,5,0-2
4509141: ACT : let,6,0-1
Sorry about this, I'm probably doing something silly!
Re: Persistent Variable
To be explicit, your rule should at least contain these lines:
Edit: Fixed a typo
Code: Select all
on Rules#Timer=1 do
Let,1,[Set_Temp#GetLevel]
endon
Last edited by Ath on 23 Aug 2022, 19:53, edited 1 time in total.
/Ton (PayPal.me)
-
- Normal user
- Posts: 57
- Joined: 28 Sep 2020, 13:58
Re: Persistent Variable
I notice you added a comma - but that didn't help. endon is included - puzzled now!
Re: Persistent Variable
You forgot the "endon" indeed.
The comma is a typo from Ton.
The comma is a typo from Ton.
Code: Select all
on Rules#Timer=1 do
Let,1,[Set_Temp#GetLevel]
endon
-
- Normal user
- Posts: 57
- Joined: 28 Sep 2020, 13:58
Re: Persistent Variable
No I didn't forget the endon. I just didn't post the full script:
Code: Select all
On System#Boot do
GPIO,0,0
oledframedcmd,linecount,2
oledframedcmd,display,high
oledframedcmd,1,Target:
oledframedcmd,2,[Set_Temp#GetLevel]
delay,2000
timerSet,1,2
endon
On Rules#Timer=1 do
// Target temp
let,1,[Set_Temp,#GetLevel]
let,2,[VAR#1]-33
let,3,[VAR#1]-15
let,4,[VAR#1]-7
let,5,[VAR#1]-2
let,6,[VAR#1]-1
let,12,[VAR#1]+2
let,10,[TEMP#Temperature]
oledframedcmd,1,[INT#10]°c
oledframedcmd,2,
if [Disable#Element]=0 AND [TEMP#Temperature]>0
if [TEMP#Temperature]<[VAR#2] AND [Pump#State]=0
GPIO,0,1
oledframedcmd,2,100%
else
GPIO,0,0
if [TEMP#Temperature]>[VAR#2] AND [TEMP#Temperature]<[VAR#4]
let,7,([VAR#1]-[TEMP#Temperature])*10
PWM,0,[INT#7]
let,8,[INT#7]/10
oledframedcmd,2,[INT#8]%
endif
if [TEMP#Temperature]>[VAR#4] AND [TEMP#Temperature]<[VAR#1]
let,7,([VAR#1]-[TEMP#Temperature])*70
PWM,0,[INT#7]
let,8,[INT#7]/10
oledframedcmd,2,[INT#8]%
delay,3000
GPIO,0,0
oledframedcmd,2,
if [TEMP#Temperature]>[VAR#6]
delay,10000
else
delay,5000
endif
endif
if [TEMP#Temperature]>[VAR#1]
oledframedcmd,2,
endif
endif
else
GPIO,0,0
endif
if [Pump#State]=1 AND [TEMP#Temperature]<[VAR#12]
PWM,0,200
oledframedcmd,2,'20% Brew!'
endif
timerSet,1,2
endon
Re: Persistent Variable
please don't use delay in rules.
That's an absolute big no-no.
There are timers, you can act on events like WiFi#connected etc.
That's an absolute big no-no.
There are timers, you can act on events like WiFi#connected etc.
Re: Persistent Variable
Those OledFramed commands can also be set in the configuration for that device, no need to do that from rules.
Restarting the timer at the end isn't needed, you can use a LoopTimerSet command, that repeats that timer indefinitely or a predefined number of times (3rd option). I'd use a bit more than 2 seconds, though, that huge rule will keep the ESP quite busy.
For readability you might want to remove the excess tabs, spaces and blank lines, as currently it isn't very comprehensible.
Restarting the timer at the end isn't needed, you can use a LoopTimerSet command, that repeats that timer indefinitely or a predefined number of times (3rd option). I'd use a bit more than 2 seconds, though, that huge rule will keep the ESP quite busy.
For readability you might want to remove the excess tabs, spaces and blank lines, as currently it isn't very comprehensible.
/Ton (PayPal.me)
-
- Normal user
- Posts: 57
- Joined: 28 Sep 2020, 13:58
Re: Persistent Variable
Thanks for the coding tips - I will optimise it with your suggestions.
But back to the persistent problem - can you see why that won't work?
But back to the persistent problem - can you see why that won't work?
Re: Persistent Variable
IMHO, my reply #5 is the correct way to store a different value in the Level Control.
And you can either use the 'save' command to store it persistently, or enable the 'Save...' checkbox in the device configuration to have it persisted immediately on change (not recommeended), until PR #4219 is merged that can save it after a set interval once changed (also can be changed multiple times before it is saved, only the first change starts the interval timer, and if the original value is set again no 'save' is applied).
And you can either use the 'save' command to store it persistently, or enable the 'Save...' checkbox in the device configuration to have it persisted immediately on change (not recommeended), until PR #4219 is merged that can save it after a set interval once changed (also can be changed multiple times before it is saved, only the first change starts the interval timer, and if the original value is set again no 'save' is applied).
/Ton (PayPal.me)
-
- Normal user
- Posts: 57
- Joined: 28 Sep 2020, 13:58
Re: Persistent Variable
Ath - I'm not disagreeing with you at all - and I'm really grateful for your help.
In fact, I'm so grateful that such a powerful tool (ESP EASY) is available for free. To have made so much progress with this project with so little programming is amazing. Thank you!
I agree that what you have suggested should work - it's just that I can't get it to work on my ESP.
Tony
In fact, I'm so grateful that such a powerful tool (ESP EASY) is available for free. To have made so much progress with this project with so little programming is amazing. Thank you!
I agree that what you have suggested should work - it's just that I can't get it to work on my ESP.
Tony
Re: Persistent Variable
That's quite easy to confirm,
1) copy the next code: (assuming that your current setting <> 89, else choose a different value than 89)
Code: Select all
config,task,Set_Temp,SetLevel,89
3) Response (Command Output) should be OK
4) Go to the Devices tab and open the device with name Set_Temp
5) The 'Set Level' should be the value you used in step 1 -> Success!
6) Go back to the Tools tab, and enter in the Command field:
Code: Select all
[Set_Temp#GetLevel]
7) The Command Output should be "Command unknown: 89.00" (or the value you entered in step 1) -> Success again!
/Ton (PayPal.me)
-
- Normal user
- Posts: 57
- Joined: 28 Sep 2020, 13:58
Re: Persistent Variable
Re: Persistent Variable
What does the "Set Level" part of the Device Configuration page show?
/Ton (PayPal.me)
Re: Persistent Variable
And what exact build of ESPEasy do you have installed (lower-right of most webpages of your ESP)
/Ton (PayPal.me)
Re: Persistent Variable
Also is the task enabled?
Re: Persistent Variable
I'm seeing something peculiar with that build when I compile and run it locally. Can you replace it by the normal normal build: ESP_Easy_mega_20220809_normal_ESP8266_4M1M and try this again?wiredcharlie wrote: ↑24 Aug 2022, 12:03 Build: ESP_Easy_mega_20220809_normal_302_ESP8266_4M1M Aug 9 2022
I also have a fix, but that will on earliest be included in a next release.
/Ton (PayPal.me)
-
- Normal user
- Posts: 57
- Joined: 28 Sep 2020, 13:58
Re: Persistent Variable
Sorry, I don't understand:
normal normal build: ESP_Easy_mega_20220809_normal_ESP8266_4M1M
normal normal build: ESP_Easy_mega_20220809_normal_ESP8266_4M1M
-
- Normal user
- Posts: 57
- Joined: 28 Sep 2020, 13:58
Re: Persistent Variable
Sorry - I have 302 - whatever that is!?
-
- Normal user
- Posts: 57
- Joined: 28 Sep 2020, 13:58
Re: Persistent Variable
Works with:
ESP_Easy_mega_20220809_normal_ESP8266_4M1M
I didn't notice the "302" when I loaded it. what does it mean?
Thanks
Tony
ESP_Easy_mega_20220809_normal_ESP8266_4M1M
I didn't notice the "302" when I loaded it. what does it mean?
Thanks
Tony
Re: Persistent Variable
esp8266/Arduino SDK 3.0.2
Ton is already looking into it, but it seems there is something strange happening with the newest SDK code.
Ton is already looking into it, but it seems there is something strange happening with the newest SDK code.
Re: Persistent Variable
I've applied a fix in the PR I opened for this plugin to add the Auto-save option.
The normal 'normal' builds for ESP8266 use the 2.7.4 version of that Core library.
The normal 'normal' builds for ESP8266 use the 2.7.4 version of that Core library.
/Ton (PayPal.me)
-
- Normal user
- Posts: 57
- Joined: 28 Sep 2020, 13:58
Re: Persistent Variable
Thanks for your help.
What's wrong with Delay? And is there a drop in alternative?
Tony
My loop drives a heater. It applies heat for a set period, then waits before checking the effect. The Delay provides a comprehensible way of doing this. I assume the alternative is to break the whole lot up into separate parts triggered by timers - but that would be harder to understand.please don't use delay in rules.
That's an absolute big no-no.
What's wrong with Delay? And is there a drop in alternative?
Tony
Re: Persistent Variable
A delay 'stops the world' in RTOS, the underlying OS of ESPEasy, so disrupts the entire processing of events like 10 per second, 50 per second and once per second, required for a lot of sensors to work as intended. If you use f.e. DS18b20, BME280 or DHT11/12/22 temperature sensors, these heavily rely on the expected timing of those events. If you delay that f.e. by 10 seconds, that would totally confuse/invalidate the measurements.wiredcharlie wrote: ↑27 Aug 2022, 09:59...please don't use delay in rules.
That's an absolute big no-no.
What's wrong with Delay? And is there a drop in alternative?
No drop-in replacement (it would have replaced the delay() function long ago), other than using timers. Proper documentation on what's going on in your code is key, I guess.
/Ton (PayPal.me)
Who is online
Users browsing this forum: No registered users and 3 guests