EspEasy,relay recovery the last state after power failure

Everything about esp8266 and more.
Post Reply
onizuka
Posts: 2
Joined: Wednesday 29 November 2017 1:31
Target OS: Raspberry Pi
Domoticz version:
Contact:

EspEasy,relay recovery the last state after power failure

Post by onizuka » Wednesday 29 November 2017 1:34

Hello to all, i've tried to search on the forum but I have not found a clear solution.
I have this scenario:
Domoticz 3.8153 on a raspberry pi
1 esp8266 flashed with esp easy v2.0.0-dev12 and a 4 relay modules

for now i've configured only 1 relay, but the problem is simple, i can control the relay using the domoticz web page using:
http://esp_ip_addr/control?cmd=GPIO,0,0
http://esp_ip_addr/control?cmd=GPIO,0,0
and all works fine, but if i reboot the esp, the relay state it is not mantained.
I think that the best solution is to ask at the domoticz controller to give me the state of that relay but i'm not able to do that
Anyone can help me?

SweetPants
Posts: 2254
Joined: Friday 12 July 2013 21:24
Target OS: Linux
Domoticz version: V4.9999
Location: The Netherlands
Contact:

Re: EspEasy,relay recovery the last state after power failure

Post by SweetPants » Wednesday 29 November 2017 9:17

This is why i use MQTT with retained messages. If the ESP module is rebooted, loses connection and re-connects to the broker, the broker sends the last 'known state' to my relay. Even if domoticz changes the state during the disconnect state, the relay is updated with this last state.
Ubuntu 16.04.3 LTS, Intel NUC, MySensors 2.3.0-alpha, Pro Mini 3.3/8M RFM69(HW), ESP8266 (SDK2.2.0), Sonoff, RFLink, RFXcom, MQTT, NodeRed, Domoticz Beta (from source)

onizuka
Posts: 2
Joined: Wednesday 29 November 2017 1:31
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: EspEasy,relay recovery the last state after power failure

Post by onizuka » Wednesday 29 November 2017 11:00

SweetPants wrote:
Wednesday 29 November 2017 9:17
This is why i use MQTT with retained messages. If the ESP module is rebooted, loses connection and re-connects to the broker, the broker sends the last 'known state' to my relay. Even if domoticz changes the state during the disconnect state, the relay is updated with this last state.
Ok i know this possibility but i'm not able to configure that...i have done in this way
IN DOMOTICZ
In Hadware i have set this:
1.jpg
1.jpg (244.19 KiB) Viewed 1725 times
but i don't know how to set the actions for power on and power off (this is the device with idx 1)
2.jpg
2.jpg (244.26 KiB) Viewed 1725 times
IN ESP:
3.jpg
3.jpg (227.82 KiB) Viewed 1725 times
i have this configuration, but the log (last picture) give me that error

kimot
Posts: 55
Joined: Saturday 25 November 2017 18:18
Target OS: Raspberry Pi
Domoticz version: v3.8153
Location: Czech Rep.
Contact:

Re: EspEasy,relay recovery the last state after power failure

Post by kimot » Wednesday 29 November 2017 22:27

I am using ESPEasy too.
For setting ESPeasy state according Domoticz after rebooting, I send status every minute to ESPEasy through LUA or dzVents.
Here is example for resending actual thermostat setpoint.
Setpoint is send immediately when changed :

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 = {
		devices = {
			-- timer triggers.. if one matches with the current time then the script is executed
			'Kacka_Setpoint'
		}
	},

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

		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
	  --if (device.name == 'Vychod_Setpoint') then
            -- local DomValue=device.state
            -- print(device.state)
            -- local CalcValue = (DomValue*1)
            -- print(CalcValue)
            local url= 'http://192.168.1.102/control?cmd=event,HeatSetpoint='..(device.state)..''
            print(url)
            domoticz.openURL(url)
       -- end
        --if (device.name == 'Vychod_Control') then
        --    local DomValue=device.level
        --    print(device.level)
            -- local CalcValue = (DomValue*1)
            -- print(CalcValue)
        --    local url= 'http://192.168.1.102/control?cmd=event,modeSet='..(device.level)..''
        --    print(url)
        --    domoticz.openURL(url)
        --end
            --commandArray['OpenURL']= url
                
                
        -- do something
           
        
	end
And then every 60 seconds with other information for others sensors too:
( look at "HDO_PV" - it is switch in domoticz and its state is send to ESPEasy every minute too)

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)
		    --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)
            -- 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
This way I have got actual state of ESPEasy within 1 minute after reboot.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest