Page 1 of 1

Store Espeasy State

Posted: 04 Mar 2018, 15:21
by tonse
I have Esp8266 relay in Spain. Elektricity and Wifi are a bit unreliable.
SO i give the esp8266 commands with user variables. PumpSchedule=1
Depending on the number i want to make an on/off schedule that is totally run on the esp itself. No other commands would be needed, so the epseay functions standalone. It only reports through MQTT or HTTP the on/off state. This i can manage.

QUestion is: How can i "store" the eventvalue, so i can run the correct schedule after a powerloss (=reboot) using on System#boot.
I use domoticz and i am considering moving to homeAssistant. This depends on the ability of either one of them to support the storage of a state and the ability of espeasy to "ask" the current state to either Domoticz or HomeAssistant. THis is the second best option. The best would be: The value is stored locally on the ESP

Re: Store Espeasy State

Posted: 04 Mar 2018, 17:13
by TD-er
I guess it would be best to add a rule to restore the desired situation using the on reboot event.
And when set, allow the timer based rules to process.

Especially with operating a pump, you don't want to have the incorrect state on for hours.

Re: Store Espeasy State

Posted: 04 Mar 2018, 19:28
by tonse
That I Know. I try to clearify it a bit more
Scheme1: Pump 1 hour a day
Scheme2: Pump 4 hourse a day
Scheme3: Pump 2x2 hours a day
Scheme4: Pump 8 hours a day

Question is: How do i return to my previouw Scheme. How can i have the Esp "remember" which scheme it was is before the powerloss

Re: Store Espeasy State

Posted: 04 Mar 2018, 20:13
by vader
With MQTT it should not be a problem. For me this works and the ESP restores the last state after reboot. ;)

Re: Store Espeasy State

Posted: 04 Mar 2018, 20:18
by Domosapiens
Not supported yet in ESPEasy, but nice ;)
https://nl.aliexpress.com/item/FM24CLXX ... Title=true

Or .. Wemos D1 with battery shield?
In Spain ... maintained by a solar cell.

Re: Store Espeasy State

Posted: 04 Mar 2018, 20:42
by TD-er
Domosapiens wrote: 04 Mar 2018, 20:18 Not supported yet in ESPEasy, but nice ;)
https://nl.aliexpress.com/item/FM24CLXX ... Title=true
[...]
You'll never know ;) https://github.com/letscontrolit/ESPEasy/issues/1011

Re: Store Espeasy State

Posted: 05 Mar 2018, 14:39
by kimot
I have got the same problem with my ESPeasy thermostat.
Not only power loss, but randomly reboot.
So I am sending correct values every minutes from Domoticz to ESPeasy through LUA scripts.

If I was not lazy:
I define user variable "ESP_003_BOOT" in Domoticz and set it to 0.
When ESPeasy boots, I change this variable to 1 via JSON API.
Domoticz script detects this change and sends actual values to ESP and resets variable back to 0.

Re: Store Espeasy State

Posted: 05 Mar 2018, 20:52
by tonse
Hi kimot
Can you send me the (part of) the LUA script?
Thanks
Ton

Re: Store Espeasy State

Posted: 06 Mar 2018, 20:34
by kimot
dzVents:

Code: Select all

-- Check the wiki at
-- http://www.domoticz.com/wiki/%27dzVents%27:_next_generation_LUA_scripting
return {

	-- 'active' controls if this entire script is considered or not
	active = true, -- set to false to disable this script

	-- trigger
	-- can be a combination:
	on = {
		timer = {
			-- timer triggers.. if one matches with the current time then the script is executed
			'every minute',
		}
	},

	-- actual event code
	-- in case of a timer event or security event, device == nil
	execute = function(domoticz)
		--[[

		The domoticz object holds all information about your Domoticz system. E.g.:

		local myDevice = domoticz.devices('myDevice')
		local myVariable = domoticz.variables('myUserVariable')
		local myGroup = domoticz.groups('myGroup')
		local myScene = domoticz.sceneds('myScene')

		The device object is the device that was triggered due to the device in the 'on' section above.
		]] --
		-- example
		    local HDO_PV = domoticz.devices('HDO-PV')
		    -- Kacka
		    local urlHDO = 'http://192.168.1.102/control?cmd=event,HDO='..(HDO_PV.nValue)..'' 
		    print(urlHDO)
		    domoticz.openURL(urlHDO)
		    -- Filip
		    local urlHDO = 'http://192.168.1.105/control?cmd=event,HDO='..(HDO_PV.nValue)..'' 
		    print(urlHDO)
		    domoticz.openURL(urlHDO)
		    --Kuchyne
		    local urlHDO = 'http://192.168.1.103/control?cmd=event,HDO='..(HDO_PV.nValue)..'' 
		    print(urlHDO)
		    domoticz.openURL(urlHDO)
		    --Obyvak
		    local urlHDO = 'http://192.168.1.104/control?cmd=event,HDO='..(HDO_PV.nValue)..'' 
		    print(urlHDO)
		    domoticz.openURL(urlHDO)
		      
	        -- Kacka
	        local setpoint = domoticz.devices('Kacka_Setpoint')
            local url= 'http://192.168.1.102/control?cmd=event,HeatSetpoint='..(setpoint.state)..''
            print(url)
            domoticz.openURL(url)
            local mode = domoticz.devices('Kacka_Control')
            local url2= 'http://192.168.1.102/control?cmd=event,modeSet='..(mode.level)..''
            print(url2)
            domoticz.openURL(url2)
             -- Filip
	        local setpoint = domoticz.devices('Filip_Setpoint')
            local url= 'http://192.168.1.105/control?cmd=event,HeatSetpoint='..(setpoint.state)..''
            print(url)
            domoticz.openURL(url)
            local mode = domoticz.devices('Filip_Control')
            local url2= 'http://192.168.1.105/control?cmd=event,modeSet='..(mode.level)..''
            print(url2)
            domoticz.openURL(url2)
            -- Kuchyne    
            local setpoint = domoticz.devices('Kuchyne_Setpoint')
            local url= 'http://192.168.1.103/control?cmd=event,HeatSetpoint='..(setpoint.state)..''
            print(url)
            domoticz.openURL(url)
            local mode = domoticz.devices('Kuchyne_Obyvak_Control')
            local url2= 'http://192.168.1.103/control?cmd=event,modeSet='..(mode.level)..''
            print(url2)
            domoticz.openURL(url2)
            -- Obyvak nastaveni stejne jako pro kuchyn, nema vlastni ovladani    
            local setpoint = domoticz.devices('Kuchyne_Setpoint')
            local url= 'http://192.168.1.104/control?cmd=event,HeatSetpoint='..(setpoint.state)..''
            print(url)
            domoticz.openURL(url)
            local mode = domoticz.devices('Kuchyne_Obyvak_Control')
            local url2= 'http://192.168.1.104/control?cmd=event,modeSet='..(mode.level)..''
            print(url2)
            domoticz.openURL(url2)
                
        -- do something
     
	end
}

Re: Store Espeasy State

Posted: 25 May 2021, 18:04
by tonse
HI
I finally managed and like to have some comment
1. I can set startingtimes and durations of a pump relay
2. In nodered i gather al the values and compose a rules2.txt file
Rules2.txt begins with: On NewValues do
...
in the event I set 4 values in 2 dummy devices. (total of 8 values)
3. I send the rules2.txt to the espeasy with a POST command
4 i call Event, Newvalues (as i also do on system#reboot)
5 in Rules1 all the events with the dunnydevice values are handled.

What did i achieve:
I can reschedule the esp and even after a powerloss and connection failures aftwer reboort that sometimes happen, i have a more or less standalone working device.