Page 1 of 1

state attribute and battery level evohome devices

Posted: Sunday 20 October 2019 21:58
by Bertvdw
I just did a fresh install on a rasberry pi and went to the last beta version of domoticz 4.11388
I connected my evohome system with the HGI80.

Now my scripts are not running anymore because the .state attribute has a value nil. The .active attribute does work for a HR92, but not for an extra relay i binded.
I did check the values with the <device>.dump() method and there i see the _state field is correctly filled.

I also don't see the battery levels anymore

Greetz Bert

Re: state attribute and battery level evohome devices

Posted: Sunday 20 October 2019 22:14
by waaren
Bertvdw wrote: Sunday 20 October 2019 21:58 I just did a fresh install on a rasberry pi and went to the last beta version of domoticz 4.11388. INow my scripts are not running anymore.
What was the version before this in which your scripts did work ?
Can you please enable debug logging in the script and share the logfile ?
Can you please share the script that is no longer working ?

Re: state attribute and battery level evohome devices

Posted: Tuesday 22 October 2019 11:18
by Bertvdw
Thanks for reacting so quicly.

I don't know the exact beta version anymore, but i updated the last time in the beginning of july 2019.
I had to do a fresh install because my SD card was corrupt.

Tonight i will provide you the information you asked for.

Re: state attribute and battery level evohome devices

Posted: Tuesday 22 October 2019 21:41
by Bertvdw
I did enable the logfile, can you tell me where i can find the log-file so i can share this?

Greetz Bert

Re: state attribute and battery level evohome devices

Posted: Tuesday 22 October 2019 23:45
by waaren
Bertvdw wrote: Tuesday 22 October 2019 21:41 I did enable the logfile, can you tell me where i can find the log-file so i can share this?

Greetz Bert
You can find the location of the logfile in the same file where you enabled it.
look in /etc/init.d/domoticz.sh

Re: state attribute and battery level evohome devices

Posted: Saturday 26 October 2019 23:29
by Bertvdw
Hereby i send you the files you asked for

The first results are with the line ...device.state... enabled
Script file: Script_1.txt
Logfile : domoticz_1.lua.txt
domoticzData.lua.txt

In the second test i disabled the line ...device.state...
Script file Script_2.lua.txt
Logfile : domoticz_2.txt

I also tried ...device.active... , this always gives False

Remark: I had to add .txt to the lua file, otherwise i couldn't attach them
The last two file i put in a separete post


Greetz Bert

Re: state attribute and battery level evohome devices

Posted: Saturday 26 October 2019 23:30
by Bertvdw
Herby the last two attachments.

Re: state attribute and battery level evohome devices

Posted: Sunday 27 October 2019 8:56
by waaren
Bertvdw wrote: Sunday 20 October 2019 21:58 I just did a fresh install on a rasberry pi and went to domoticz 4.11388
Now my scripts are not running anymore because the .state attribute has a value nil. The .active attribute does work for a HR92, but not for an extra relay i binded.
Can you please test below modified evohome device adapter and report your findings ?

Code: Select all

cp <domoticz dir>/dzVents/runtime/device-adapters/evohome_device.lua <domoticz dir>/dzVents/runtime/device-adapters/evohome_device.luaKeep
and replace it with this modified adapter. ( No need to restart domoticz or dzVents )
I also don't see the battery levels anymore
Can you explain in a bit more detail what you mean with his ? domoticz only reports a valid battery-level for device 'Woonkamer (V)'

Code: Select all

local TimedCommand = require('TimedCommand')

return {

	baseType = 'device',

	name = 'Evohome device adapter',

	matches = function (device, adapterManager)
		local res = (
			device.hardwareTypeValue == 39 or
			device.hardwareTypeValue == 40 or
			device.hardwareTypeValue == 106 or
			device.hardwareTypeValue == 75
		)

		if (not res) then
			adapterManager.addDummyMethod(device, 'updateSetPoint')
			adapterManager.addDummyMethod(device, 'setHotWater')
			adapterManager.addDummyMethod(device, 'setMode')
		end

		return res

	end,

	process = function (device, data, domoticz, utils, adapterManager)

		if device.deviceSubType == "Hot Water" then

			if device.rawData[2] == "On" then device.state = "On" else device.state = "Off" end
			device.mode = tostring(device.rawData[3] or "n/a")
			device.untilDate = tostring(device.rawData[4] or "n/a")

			function device.setHotWater(state, mode, untilDate)
				 if mode == 'TemporaryOverride' and untilDate then
					mode = mode .. "&until=" .. untilDate
				 end
				local url = domoticz.settings['Domoticz url'] ..
					"/json.htm?type=setused&idx=" .. device.id ..
					"&setpoint=&state=" .. state ..
					"&mode=" .. mode ..
					"&used=true"
				return domoticz.openURL(url)
			end
		elseif device.deviceSubType == "Relay" then
			if device._state == "On" then
				device.state = "On"
				device.active = true
			else
				device.state = "Off"
				device.active = false
			end
		else
			device.state = device.rawData[2]
			device.setPoint = tonumber(device.rawData[1] or 0)
			device.mode = tostring(device.rawData[3])
			device.untilDate = tostring(device.rawData[4] or "n/a")

			function device.updateSetPoint(setPoint, mode, untilDate)
				return TimedCommand(domoticz,
					'SetSetPoint:' .. tostring(device.id),
					tostring(setPoint) .. '#' ..
					tostring(mode) .. '#' ..
					tostring(untilDate) , 'setpoint')
			end

			function device.setMode(mode, dParm, action, ooc)

				local function checkTimeAndReturnISO(tm)
					local now = domoticz.time
					local iso8601Pattern = "(%d+)-(%d+)-(%d+)T(%d+):(%d+):(%d+)Z"
					local iso8601Format = "%Y-%m-%dT%TZ"

					local function inFuture(tmISO)
						local function makeFutureISOTime(str, hours)
							local xyear, xmonth, xday, xhour, xminute, xseconds = str:match(iso8601Pattern)
							local seconds = os.time({year = xyear, month = xmonth, day = xday, hour = xhour, min = xminute, sec = xseconds})
							local offset = (seconds + ( hours or 0 ) *  3600)
							return os.date(iso8601Format,offset),  offset
						end

						local _, epoch = makeFutureISOTime(tmISO)
						return epoch >= now.dDate and tmISO
					end

					if type(tm) == 'string' and tm:find(iso8601Pattern) then return inFuture(tm) end				-- Something like '2016-04-29T06:32:58Z'
					if type(tm) == 'table' and tm.getISO then return inFuture(tm.getISO()) end					  -- a dzVents time object
					if type(tm) == 'table' and tm.day then return inFuture(os.date(iso8601Format,os.time(tm))) end  -- a standard time object
					if type(tm) == 'number' and tm > now.dDate then return inFuture(os.date(iso8601Format,tm)) end  -- seconds since epoch
					if type(tm) == 'number' and tm > 0 and tm < ( 365 * 24 * 60 ) then return inFuture(os.date(iso8601Format,now.dDate + ( tm * 60 ))) end  -- seconds since epoch + tm

					domoticz.log('dParm ' .. tostring(dParm) .. ' cannot be processed. (it will be ignored)',utils.LOG_ERROR)
					return false -- not a time as we know it
				end

				local function isValid(mode)
					for _, value in pairs(domoticz) do
						local res =  type(value) == 'string' and value == mode
						if res then return res end
					end
					return mode == 'Busted' or false
				end

				local function binary(num, default)
					if num == 0 or num == 1 then return num else return default end
				end

				if isValid( tostring(mode) ) then -- is it in the list of valid modes ?
					local dParm = dParm and checkTimeAndReturnISO(dParm) -- if there is a dParm then check if valid and make a valid ISO date
					dParm = ( dParm and '&until=' .. dParm ) or ''
					local action = ( action and '&action=' .. binary(action, 1) ) or '&action=1'
					local ooc = ( ooc and '&ooc=' .. binary(ooc, 0) ) or '&ooc=0'
				   
					local url = domoticz.settings['Domoticz url'] ..
								'/json.htm?type=command&param=switchmodal&idx=' .. device.id ..
								"&status=" .. mode ..
								dParm ..
								action ..
								ooc
					return domoticz.openURL(url)
				else
					utils.log('Unknown status for setMode requested: ' .. tostring(mode),utils.LOG_ERROR)
				end
			end
		end
	end
}

Re: state attribute and battery level evohome devices

Posted: Tuesday 29 October 2019 23:11
by Bertvdw
I changed the evohome_device.lua file like you asked.
Now i can use the attibute state again.

There is still one strange thing the relay "Schuur (P)".
If i manually change the state on the physical device, then no event is triggered.
So the device attributes are not correct.

I bound the relay 'Schuur (P)' in the 'Hardware tab' with the 'Bind Relay' (See attachment).

About the batterylevel:
In the old environment all the evohome zone devices and some of the Relay devices showed the batterylevel in the devices tab.
Now only one zone device shows the batterylevel ( See attachments )

Greetz Bert

Re: state attribute and battery level evohome devices

Posted: Wednesday 30 October 2019 0:03
by waaren
Bertvdw wrote: Tuesday 29 October 2019 23:11 I changed the evohome_device.lua file like you asked. Now i can use the attibute state again.

If i manually change the state on the physical device, then no event is triggered.

In the old environment all the evohome zone devices and some of the Relay devices showed the batterylevel in the devices tab.
Will push the fix of the evohome device adapter to the next Beta
I have no clue on the relay stuf. Maybe one of the other forum members can help.
Reported the battery issue on Github. Hopefully someone can shed some light on this.

Re: state attribute and battery level evohome devices  [SOLVED]

Posted: Thursday 31 October 2019 11:02
by Bertvdw
Thank you so far for your help.

Gr. Bert