switchOn not available for ELRO AB400?  [Solved]

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
Haringstad
Posts: 13
Joined: Tuesday 22 November 2016 9:54
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

switchOn not available for ELRO AB400?

Post by Haringstad »

Hello Folks,

Getting:

Code: Select all

2017-07-18 20:41:00.241  dzVents: Info:  ------ Start internal script: Start Workday:, trigger: at 20:41 on mon,tue,wed,thu,fri
2017-07-18 20:41:00.278  Error: dzVents: Error: Method switchOn is not available for device "Bedroom Right Side" (deviceType=Lighting 1, deviceSubTyp
e=ELRO AB400). If you believe this is not correct, please report.
2017-07-18 20:41:00.279  Error: dzVents: Error: An error occured when calling event handler Start Workday
2017-07-18 20:41:00.279  Error: dzVents: Error: ...ticz/scripts/dzVents/generated_scripts/Start Workday.lua:29: attempt to index a nil value
2017-07-18 20:41:00.279  dzVents: Info:  ------ Finished Start Workday
From:

Code: Select all

-- Sunrise, turn off all kinds of lights

return {
    
	active = true, -- set to false to disable this script

	on = {
		
		timer = {
		    'at 20:41 on mon,tue,wed,thu,fri'
		}
	},
	execute = function(domoticz)
		
		local bedroom_left = domoticz.devices('Bedroom Left Side')
		local bedroom_right = domoticz.devices('Bedroom Right Side')
		local bedroom_blue_lamp = domoticz.devices('Bedroom Blue Lamp')
		local tall_lamp = domoticz.devices('Staande Lamp')
		local mirror_leds = domoticz.devices('Spiegel Leds')
		local livingroom = domoticz.devices('Huiskamer')

		if (not bedroom_left.bState) then
            local RANDOM_DELAY_MINS = 15
            bedroom_left.switchOn().withinMin(RANDOM_DELAY_MINS)
            domoticz.notify('Hey!', 'Kitchen Left Light switched on!', domoticz.PRIORITY_NORMAL)
        end
		if (not bedroom_right.bState) then
            local RANDOM_DELAY_MINS = 15
            bedroom_right.switchOn().withinMin(RANDOM_DELAY_MINS)
            domoticz.notify('Hey!', 'Kitchen Left Light switched on!', domoticz.PRIORITY_NORMAL)
        end
		if (not bedroom_blue_lamp.bState) then
            local RANDOM_DELAY_MINS = 15
            bedroom_blue_lamp.switchOn().withinMin(RANDOM_DELAY_MINS)
            domoticz.notify('Hey!', 'Kitchen Left Light switched on!', domoticz.PRIORITY_NORMAL)
        end
		if (not tall_lamp.bState) then
            local RANDOM_DELAY_MINS = 15
            tall_lamp.switchOn().withinMin(RANDOM_DELAY_MINS)
            domoticz.notify('Hey!', 'Kitchen Left Light switched on!', domoticz.PRIORITY_NORMAL)
        end
        if (not mirror_leds.bState) then
            local RANDOM_DELAY_MINS = 15
            mirror_leds.switchOn().withinMin(RANDOM_DELAY_MINS)
            domoticz.notify('Hey!', 'Kitchen Left Light switched on!', domoticz.PRIORITY_NORMAL)
        end
        
	end
}
In the regular LUA scripts, this switch functions Superb???

Regards, Jacco
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: switchOn not available for ELRO AB400?  [Solved]

Post by dannybloe »

Yes, I noticed this. 2.1.1 should detect your switch properly. If you dare you can patch it yourself and try it out. Locate the file switch_device.lua in /path/to/domoticz/scripts/dzVents/runtime/adapters and change it to:

Code: Select all

local TimedCommand = require('TimedCommand')

return {

	baseType = 'device',

	name = 'Switch device adapter',

	matches = function (device, adapterManager)
		local res = (
			device.deviceType == 'Light/Switch' or
			device.deviceType == 'Lighting 1' or
			device.deviceType == 'Lighting 2' or
			device.deviceType == 'Lighting 3' or
			device.deviceType == 'Lighting 4' or
			device.deviceType == 'Lighting 5' or
			device.deviceType == 'Lighting 6' or
			device.deviceType == 'Lighting Limitless/Applamp' or
			device.deviceType == 'Fan' or
			device.deviceType == 'Curtain' or
			device.deviceType == 'Blinds' or
			device.deviceType == 'RFY' or
			device.deviceType == 'Chime' or
			device.deviceType == 'Thermostat 2' or
			device.deviceType == 'Thermostat 3' or
			device.deviceType == 'Thermostat 4' or
			device.deviceType == 'Remote & IR' or
			device.deviceType == 'Home Confort' or -- typo should be there
			(device.deviceType == 'Radiator 1' and device.deviceSubType == 'Smartwares Mode') or
			(device.deviceType == 'Value' and device.deviceSubType == 'Rego 6XX')
		)
		if (not res) then
			adapterManager.addDummyMethod(device, 'switchOn')
			adapterManager.addDummyMethod(device, 'switchOff')
			adapterManager.addDummyMethod(device, 'close')
			adapterManager.addDummyMethod(device, 'open')
			adapterManager.addDummyMethod(device, 'stop')
			adapterManager.addDummyMethod(device, 'dimTo')
			adapterManager.addDummyMethod(device, 'switchSelector')
			adapterManager.addDummyMethod(device, 'toggleSwitch')
		end
		return res
	end,

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

		-- from data: levelName, levelOffHidden, levelActions, maxDimLevel

		if (data.lastLevel ~= nil) then
			-- dimmers that are switched off have a last level
			device.lastLevel = data.lastLevel
		end

		if (device.level == nil and data.data._nValue ~= nil) then
			-- rgb devices get their level in _nValue
			device.level = data.data._nValue
		end


		function device.toggleSwitch()
			local current, inv
			if (device.state ~= nil) then
				current = adapterManager.states[string.lower(device.state)]
				if (current ~= nil) then
					inv = current.inv
					if (inv ~= nil) then
						return TimedCommand(domoticz, device.name, inv)
					end
				end
			end
			return nil
		end

		function device.switchOn()
			return TimedCommand(domoticz, device.name, 'On')
		end

		function device.switchOff()
			return TimedCommand(domoticz, device.name, 'Off')
		end

		function device.close()
			return TimedCommand(domoticz, device.name, 'Off')
		end

		function device.open()
			return TimedCommand(domoticz, device.name, 'On')
		end

		function device.stop() -- blinds
			return TimedCommand(domoticz, device.name, 'Stop')
		end

		function device.dimTo(percentage)
			return TimedCommand(domoticz, device.name, 'Set Level ' .. tostring(percentage))
		end

		function device.switchSelector(level)
			return TimedCommand(domoticz, device.name, 'Set Level ' .. tostring(level))
		end

		if (device.switchType == 'Selector') then
			device.levelNames = device.levelNames and string.split(device.levelNames, '|') or {}
			device.level = tonumber(device.rawData[1])
			device.levelName = device.state

		end

	end

}
and trigger your script again.

Please let me know if this works for you.

Cheers,
Danny
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
Haringstad
Posts: 13
Joined: Tuesday 22 November 2016 9:54
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: switchOn not available for ELRO AB400?

Post by Haringstad »

@dannybloe

Works like a CHARM!!! THNX!
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: switchOn not available for ELRO AB400?

Post by dannybloe »

Cool. I'll commit the change then :) Thanks.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests