Trouble with variable of initiating device  [Solved]

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

Moderator: leecollings

Post Reply
ZatarraNL
Posts: 28
Joined: Saturday 16 September 2017 9:02
Target OS: Linux
Domoticz version: 4.10717
Location: Netherlands
Contact:

Trouble with variable of initiating device

Post by ZatarraNL »

I'm giving dzVents a try for triggering some of my devices. I'm quite unfamiliar with scripting, but dzVents looks like something suitable for my needs.

I have read the complete tutorial on the Wiki "DzVents: next generation LUA scripting" and have seen the complete dzVents starters Video on Youtube, made by Dannybloe. Great video btw!

One thing that is not clear to me: how can I use variables of the triggering device for other devices. My case:
I have 3 identical Ikea Tradfri bulbs, connected via zigbee2mqtt. I want to copy all changes of bulb1 to bulb2 and bulb3. I can copy the on/off status, but not the light temperature and the dim percentages.

Currently my script is:

Code: Select all

return {
	on = {
		devices = {	
		    'Tafellamp1'
		    }
	},
	execute = function(domoticz, device)
        domoticz.log('Tafellamp1 geactiveerd')
		domoticz.log(device.state)
		if (device.state == 'Off') then
		    domoticz.devices('Tafellamp3').switchOff()
		    domoticz.devices('Tafellamp2').switchOff()
		    domoticz.log('tafellampen zijn uit', domoticz.LOG_INFO)
		elseif (device.state == 'On') then
		    domoticz.log(color, domoticz.LOG_INFO)
		    domoticz.devices('Tafellamp1').getkelvinlevel(kelvin)
		    domoticz.devices('Tafellamp2').switchOn()
		    domoticz.devices('Tafellamp3').switchOn()
		    domoticz.devices('Tafellamp2').dimTo(percentage)
		    domoticz.devices('Tafellamp2').setKelvin(kelvin)
		    domoticz.devices('Tafellamp3').dimTo(percentage)
		    domoticz.devices('Tafellamp3').setKelvin(kelvin)
		    domoticz.log('tafellampen zijn aan', domoticz.LOG_INFO)
		end
	end
}
The 'off' part works. All the other doesn't. I get errors like

Code: Select all

lua:16: attempt to call field 'getkelvinlevel' (a nil value)
Can anybody point me in the right direction?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Trouble with variable of initiating device

Post by waaren »

ZatarraNL wrote: Monday 23 September 2019 16:02 One thing that is not clear to me: how can I use variables of the triggering device for other devices. My case:
The 'off' part works. All the other doesn't. I get errors like

Code: Select all

lua:16: attempt to call field 'getkelvinlevel' (a nil value)
You use percentage, kelvin and getkelvinlevel without defining these variables / methods anywhere in your script. That will not work.
There is no defined method to get the Kelvin value in domoticz / dzVents. Probably the closest you can get to what you intend is this.

Code: Select all

return {
	on = {
		devices = {	
		    'Tafellamp1',
		    }
	},
	execute = function(domoticz, device)
        domoticz.log('Tafellamp1 geactiveerd')
		domoticz.log(device.state)
		if (device.state == 'Off') then
		     domoticz.devices('Tafelllamp2').switchOff()
		     domoticz.devices('Tafelllamp3').switchOff()
		     domoticz.log('tafellampen zijn uit', domoticz.LOG_INFO)
		elseif device.state == 'On' then
		     domoticz.log(device.color, domoticz.LOG_INFO)
		     domoticz.devices('Tafellamp2').dimTo(device.level)
		     domoticz.devices('Tafellamp3').dimTo(device.level)
	             domoticz.devices('Tafellamp2').setkelvin(device.color.br)
	  	     domoticz.devices('Tafellamp3').setkelvin(device.color.br)
		     domoticz.log('tafellampen zijn aan', domoticz.LOG_INFO)
		end
	end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
ZatarraNL
Posts: 28
Joined: Saturday 16 September 2017 9:02
Target OS: Linux
Domoticz version: 4.10717
Location: Netherlands
Contact:

Re: Trouble with variable of initiating device

Post by ZatarraNL »

Thanks @Waaren, that helps a lot:

The dim state is copied this way. So that fixes the dimming of the bulbs.

Now the temperature. Unfortunately, this doesn't work yet. Here the result of some code with the corresponding errors:

Code: Select all

domoticz.devices('Tafellamp3').setkelvin(device.color.br)
or

Code: Select all

domoticz.devices('Tafellamp3').setkelvinlevel(device.level)
or

Code: Select all

domoticz.devices('Tafellamp3').setcolor(device.level)
Result in the error:
attempt to call field 'setkelvin' (a nil value).

When I do this:

Code: Select all

domoticz.devices('Tafellamp3').setColor(device.level)
or

Code: Select all

domoticz.devices('Tafellamp3').setColor(device.color.br)
Result in the error:
Error (2.4.19): RGB values need to be numbers from 0-255.

When I do this:

Code: Select all

domoticz.devices('Tafellamp3').setKelvin(device.level)
or

Code: Select all

domoticz.devices('Tafellamp3').setKelvin(device.color.br)
Result in the error:
Error (2.4.19): Method setKelvin is not available for device "Tafellamp3" (deviceType=Color Switch, deviceSubType=WW). If you believe this is not correct, please report.

So my careful conclusion is:
1. Capital letters matter (setkelvin versus setKelvin)
2. When using an unknown attribute we get the error "a nil value" (it doens't recognize setkelvin)
3. The bulbs are not suitable for the "setKelvin" command (see last error)
4. The bulbs are maybe suitable for the "setColor" command, but I don't know how to set the value yet (see 2nd error)

My question now is: Is the setColor the right attribute? And, what kind of value should RGB be if 0-255 is required?
Note: I don't have RGB lights, but only temperature can change.

When I change the temperature of the bulbs manually, I get the following feedback in the log. The RGB value stays constant (000000), but the t-value, CWWW-value and CT-value changes.
Status: setkelvinlevel: t: 14.000000, color: '{m: 2, RGB: 000000, CWWW: db24, CT: 36}
Last edited by ZatarraNL on Tuesday 24 September 2019 18:47, edited 2 times in total.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Trouble with variable of initiating device

Post by waaren »

ZatarraNL wrote: Tuesday 24 September 2019 16:42 Now the temperature. Unfortunately, this doesn't work yet.
What do you think?
First need to know what type of devices ( as recognized by domoticz / dzVents) we are dealing with.
Please execute this script and collect complete log from one execution.

Code: Select all

return {
	on = {
		devices = {	
		    'Tafellamp1',
		    }
	},
	execute = function(domoticz, device)
        domoticz.log('Tafellamp1 geactiveerd')
		domoticz.log(device.state)
		if (device.state == 'Off') then
		     domoticz.devices('Tafelllamp2').switchOff()
		     domoticz.devices('Tafelllamp3').switchOff()
		     domoticz.log('tafellampen zijn uit', domoticz.LOG_INFO)
		elseif device.state == 'On' then
		     domoticz.log(device.color, domoticz.LOG_INFO)
		     domoticz.devices('Tafellamp2').dimTo(device.level)
		     domoticz.devices('Tafellamp3').dimTo(device.level)
	         domoticz.log('tafellampen zijn aan', domoticz.LOG_INFO)
		end
		device.dump()
	end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
ZatarraNL
Posts: 28
Joined: Saturday 16 September 2017 9:02
Target OS: Linux
Domoticz version: 4.10717
Location: Netherlands
Contact:

Re: Trouble with variable of initiating device

Post by ZatarraNL »

The requested result of the log:

Code: Select all

2019-09-24 18:39:20.301 Status: dzVents: > isToday: true
2019-09-24 18:39:20.301 Status: dzVents: > matchesRule()
2019-09-24 18:39:20.301 Status: dzVents: > compare()
2019-09-24 18:39:20.301 Status: dzVents: > ruleIsAfterSunrise()
2019-09-24 18:39:20.301 Status: dzVents: > ruleMatchesBetweenRange()
2019-09-24 18:39:20.301 Status: dzVents: > milliseconds: 0
2019-09-24 18:39:20.301 Status: dzVents: > ruleMatchesTime()
2019-09-24 18:39:20.301 Status: dzVents: > msAgo: 2404790
2019-09-24 18:39:20.301 Status: dzVents: > ruleMatchesTimeRange()
2019-09-24 18:39:20.301 Status: dzVents: > day: 24
2019-09-24 18:39:20.301 Status: dzVents: > ruleMatchesHourSpecification()
2019-09-24 18:39:20.302 Status: dzVents: > ruleIsBeforeCivilTwilightEnd()
2019-09-24 18:39:20.302 Status: dzVents: > ruleMatchesMinuteSpecification()
2019-09-24 18:39:20.302 Status: dzVents: > ruleIsAtDayTime()
2019-09-24 18:39:20.302 Status: dzVents: > ruleIsAtNight()
2019-09-24 18:39:20.302 Status: dzVents: > year: 2019
2019-09-24 18:39:20.302 Status: dzVents: > ruleIsAtCivilDayTime()
2019-09-24 18:39:20.302 Status: dzVents: > rawTime: 17:59:16
2019-09-24 18:39:20.302 Status: dzVents: > ruleIsAfterSunset()
2019-09-24 18:39:20.302 Status: dzVents: > ruleIsOnDay()
2019-09-24 18:39:20.302 Status: dzVents: > ruleIsBeforeSunset()
2019-09-24 18:39:20.302 Status: dzVents: > ruleIsAtSunset()
2019-09-24 18:39:20.302 Status: dzVents: > dDate: 1569340756
2019-09-24 18:39:20.309 Status: dzVents: > getISO()
2019-09-24 18:39:20.309 Status: dzVents: > utils:
2019-09-24 18:39:20.310 Status: dzVents: > hsbToRGB()
2019-09-24 18:39:20.310 Status: dzVents: > print()
2019-09-24 18:39:20.310 Status: dzVents: > urlEncode()
2019-09-24 18:39:20.310 Status: dzVents: > fromJSON()
2019-09-24 18:39:20.310 Status: dzVents: > urlDecode()
2019-09-24 18:39:20.310 Status: dzVents: > LOG_ERROR: 1
2019-09-24 18:39:20.310 Status: dzVents: > osExecute()
2019-09-24 18:39:20.310 Status: dzVents: > log()
2019-09-24 18:39:20.310 Status: dzVents: > rgbToHSB()
2019-09-24 18:39:20.310 Status: dzVents: > LOG_MODULE_EXEC_INFO: 2
2019-09-24 18:39:20.310 Status: dzVents: > dumpTable()
2019-09-24 18:39:20.310 Status: dzVents: > LOG_FORCE: 0.5
2019-09-24 18:39:20.310 Status: dzVents: > stringSplit()
2019-09-24 18:39:20.310 Status: dzVents: > DZVERSION: 2.4.19
2019-09-24 18:39:20.310 Status: dzVents: > toJSON()
2019-09-24 18:39:20.310 Status: dzVents: > LOG_INFO: 3
2019-09-24 18:39:20.310 Status: dzVents: > LOG_DEBUG: 4
2019-09-24 18:39:20.310 Status: dzVents: > fileExists()
2019-09-24 18:39:20.310 Status: dzVents: > isdst: true
2019-09-24 18:39:20.310 Status: dzVents: > dayAbbrOfWeek: tue
2019-09-24 18:39:20.310 Status: dzVents: > ruleIsAfterCivilTwilightEnd()
2019-09-24 18:39:20.310 Status: dzVents: > ruleIsAtCivilTwilightEnd()
2019-09-24 18:39:20.310 Status: dzVents: > ruleIsAfterCivilTwilightStart()
2019-09-24 18:39:20.310 Status: dzVents: > sec: 16
2019-09-24 18:39:20.310 Status: dzVents: > min: 59
2019-09-24 18:39:20.311 Status: dzVents: > ruleIsAtCivilTwilightStart()
2019-09-24 18:39:20.311 Status: dzVents: > wday: 3
2019-09-24 18:39:20.311 Status: dzVents: > ruleIsInWeek()
2019-09-24 18:39:20.311 Status: dzVents: > ruleIsOnDate()
2019-09-24 18:39:20.311 Status: dzVents: > hoursAgo: 0
2019-09-24 18:39:20.311 Status: dzVents: > current:
2019-09-24 18:39:20.311 Status: dzVents: > day: 24
2019-09-24 18:39:20.311 Status: dzVents: > month: 9
2019-09-24 18:39:20.311 Status: dzVents: > min: 39
2019-09-24 18:39:20.311 Status: dzVents: > isdst: true
2019-09-24 18:39:20.311 Status: dzVents: > wday: 3
2019-09-24 18:39:20.311 Status: dzVents: > yday: 267
2019-09-24 18:39:20.311 Status: dzVents: > year: 2019
2019-09-24 18:39:20.311 Status: dzVents: > hour: 18
2019-09-24 18:39:20.311 Status: dzVents: > sec: 20
2019-09-24 18:39:20.311 Status: dzVents: > secondsSinceMidnight: 64756
2019-09-24 18:39:20.311 Status: dzVents: > ruleIsAtSunrise()
2019-09-24 18:39:20.311 Status: dzVents: > minutesAgo: 40
2019-09-24 18:39:20.311 Status: dzVents: > raw: 2019-09-24 17:59:16
2019-09-24 18:39:20.311 Status: dzVents: > ruleIsBeforeSunrise()
2019-09-24 18:39:20.311 Status: dzVents: > milliSeconds: 0
2019-09-24 18:39:20.311 Status: dzVents: > isUTC: false
2019-09-24 18:39:20.311 Status: dzVents: > week: 39
2019-09-24 18:39:20.312 Status: dzVents: > yday: 267
2019-09-24 18:39:20.312 Status: dzVents: > secondsAgo: 2404
2019-09-24 18:39:20.312 Status: dzVents: > daysAgo: 0
2019-09-24 18:39:20.312 Status: dzVents: > ruleIsAtCivilNight()
2019-09-24 18:39:20.312 Status: dzVents: > ruleIsBeforeCivilTwilightStart()
2019-09-24 18:39:20.312 Status: dzVents: > rawDate: 2019-09-24
2019-09-24 18:39:20.312 Status: dzVents: > month: 9
2019-09-24 18:39:20.312 Status: dzVents: > hour: 17
2019-09-24 18:39:20.312 Status: dzVents: > name: Tafellamp1
2019-09-24 18:39:20.312 Status: dzVents: > updateVoltage()
2019-09-24 18:39:20.312 Status: dzVents: > updateAlertSensor()
2019-09-24 18:39:20.312 Status: dzVents: > updateWaterflow()
2019-09-24 18:39:20.312 Status: dzVents: > isDevice: true
2019-09-24 18:39:20.312 Status: dzVents: > kodiPlayPlaylist()
2019-09-24 18:39:20.312 Status: dzVents: > updateCounter()
2019-09-24 18:39:20.312 Status: dzVents: > protected: false
2019-09-24 18:39:20.312 Status: dzVents: > decreaseBrightness()
2019-09-24 18:39:20.312 Status: dzVents: > nValue: 1
2019-09-24 18:39:20.312 Status: dzVents: Info: ------ Finished Script #1
2019-09-24 18:39:20.312 Status: dzVents: Info: ------ Start internal script: Tafellampen: Device: "Tafellamp1 (Zigbee2MQTT)", Index: 120
2019-09-24 18:39:20.312 Status: dzVents: Info: Tafellamp1 geactiveerd
2019-09-24 18:39:20.313 Status: dzVents: Info: On
2019-09-24 18:39:20.341 Status: dzVents: Info: {["value"]=0, ["m"]=2, ["cw"]=0, ["green"]=0, ["saturation"]=0, ["b"]=0, ["g"]=0, ["warm white"]=0, ["ww"]=0, ["brightness"]=0, ["hue"]=300, ["red"]=0, ["r"]=0, ["mode"]=2, ["t"]=127, ["cold white"]=0, ["temperature"]=127, ["isWhite"]=true, ["blue"]=0}
2019-09-24 18:39:20.341 Status: dzVents: Error (2.4.19): RGB values need to be numbers from 0-255
2019-09-24 18:39:20.341 Status: dzVents: Info: tafellampen zijn aan
2019-09-24 18:39:20.341 Status: dzVents: Info: ------ Finished Tafellampen
2019-09-24 18:39:20.349 Status: EventSystem: Script event triggered: /home/drijfhout/domoticz/dzVents/runtime/dzVents.lua


My own trial/errors:
domoticz.log(device.getColor, domoticz.LOG_INFO) gives me:

Code: Select all

Status: dzVents: Info: {["g"]=0, ["saturation"]=0, ["m"]=2, ["hue"]=300, ["cw"]=0, ["b"]=0, ["isWhite"]=true, ["brightness"]=0, ["temperature"]=255, ["mode"]=2, ["ww"]=0, ["cold white"]=0, ["warm white"]=0, ["red"]=0, ["blue"]=0, ["green"]=0, ["r"]=0, ["value"]=0, ["t"]=255}
This suggests that my bulbs can handle setColor.

Code: Select all

domoticz.devices('Tafellamp3').setColor(device.getColor)
Result in the error:
Error (2.4.19): RGB values need to be numbers from 0-255.

Code: Select all

domoticz.devices('Tafellamp3').setColor(device.getColor.temperature)
Result in the error:
attempt to index field 'getColor' (a function value)

Code: Select all

domoticz.devices('Tafellamp3').setColor(device.color.temperature)
Result in the error:
Error (2.4.19): RGB values need to be numbers from 0-255.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Trouble with variable of initiating device

Post by waaren »


ZatarraNL wrote: Tuesday 24 September 2019 16:42 Now the temperature.
There must be more then this but if you look at the log from inside the gui you will only see the last 100 lines.
If you are not logging to an os file, you can get all lines by starting domoticz from the commandline interface.


Verstuurd vanaf mijn ONEPLUS A6003 met Tapatalk

Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
ZatarraNL
Posts: 28
Joined: Saturday 16 September 2017 9:02
Target OS: Linux
Domoticz version: 4.10717
Location: Netherlands
Contact:

Re: Trouble with variable of initiating device

Post by ZatarraNL »

I don't know where to find the log of domoticz in the terminal. And the journalctl is empty. I tried the script again without the other scripts enabled. I got some new values. Is this enough?

Code: Select all

2019-09-24 19:48:05.337 Status: dzVents: > state: On
2019-09-24 19:48:05.337 Status: dzVents: > playFavorites()
2019-09-24 19:48:05.337 Status: dzVents: > updateYouless()
2019-09-24 19:48:05.337 Status: dzVents: > updateVoltage()
2019-09-24 19:48:05.337 Status: dzVents: > unit: 10
2019-09-24 19:48:05.338 Status: dzVents: > protected: false
2019-09-24 19:48:05.338 Status: dzVents: > updateVisibility()
2019-09-24 19:48:05.338 Status: dzVents: > updateCustomSensor()
2019-09-24 19:48:05.338 Status: dzVents: > setVolume()
2019-09-24 19:48:05.338 Status: dzVents: > updateTempHumBaro()
2019-09-24 19:48:05.338 Status: dzVents: > disarm()
2019-09-24 19:48:05.338 Status: dzVents: > timedOut: false
2019-09-24 19:48:05.338 Status: dzVents: > deviceId: 0x14b457fffe45eb9e_light
2019-09-24 19:48:05.345 Status: dzVents: > setHex()
2019-09-24 19:48:05.345 Status: dzVents: > updateSoundLevel()
2019-09-24 19:48:05.346 Status: dzVents: > cancelQueuedCommands()
2019-09-24 19:48:05.346 Status: dzVents: > updateTempHum()
2019-09-24 19:48:05.346 Status: dzVents: > setKelvin()
2019-09-24 19:48:05.346 Status: dzVents: > updateTempBaro()
2019-09-24 19:48:05.346 Status: dzVents: > isVariable: false
2019-09-24 19:48:05.346 Status: dzVents: > updateTemperature()
2019-09-24 19:48:05.346 Status: dzVents: > updateSoilMoisture()
2019-09-24 19:48:05.346 Status: dzVents: > id: 120
2019-09-24 19:48:05.346 Status: dzVents: > updateWind()
2019-09-24 19:48:05.346 Status: dzVents: > setDiscoMode()
2019-09-24 19:48:05.346 Status: dzVents: > getColor()
2019-09-24 19:48:05.346 Status: dzVents: > isGroup: false
2019-09-24 19:48:05.346 Status: dzVents: > levelVal: 60
2019-09-24 19:48:05.346 Status: dzVents: > setHue()
2019-09-24 19:48:05.346 Status: dzVents: > updatePressure()
2019-09-24 19:48:05.346 Status: dzVents: > setRGB()
2019-09-24 19:48:05.346 Status: dzVents: > updateAlertSensor()
2019-09-24 19:48:05.346 Status: dzVents: > updatePercentage()
2019-09-24 19:48:05.346 Status: dzVents: > color: {"b":0,"cw":0,"g":0,"m":2,"r":0,"t":208,"ww":0}
2019-09-24 19:48:05.346 Status: dzVents: > updateP1()
2019-09-24 19:48:05.347 Status: dzVents: > description:
2019-09-24 19:48:05.347 Status: dzVents: > nValue: 1
2019-09-24 19:48:05.347 Status: dzVents: > onkyoEISCPCommand()
2019-09-24 19:48:05.347 Status: dzVents: > updateBarometer()
2019-09-24 19:48:05.347 Status: dzVents: > volumeUp()
2019-09-24 19:48:05.347 Status: dzVents: > switchType: Dimmer
2019-09-24 19:48:05.347 Status: dzVents: > startPlaylist()
2019-09-24 19:48:05.347 Status: dzVents: > updateText()
2019-09-24 19:48:05.347 Status: dzVents: > isDevice: true
2019-09-24 19:48:05.347 Status: dzVents: > setDescription()
2019-09-24 19:48:05.347 Status: dzVents: > dump()
2019-09-24 19:48:05.347 Status: dzVents: > hardwareName: Zigbee2MQTT
2019-09-24 19:48:05.347 Status: dzVents: > isScene: false
2019-09-24 19:48:05.347 Status: dzVents: > stop()
2019-09-24 19:48:05.347 Status: dzVents: > switchOff()
2019-09-24 19:48:05.347 Status: dzVents: > baseType: device
2019-09-24 19:48:05.347 Status: dzVents: > setColor()
2019-09-24 19:48:05.347 Status: dzVents: > setHotWater()
2019-09-24 19:48:05.347 Status: dzVents: > changed: true
2019-09-24 19:48:05.347 Status: dzVents: > updateLux()
2019-09-24 19:48:05.348 Status: dzVents: > maxDimLevel: 100
2019-09-24 19:48:05.348 Status: dzVents: > setNightMode()
2019-09-24 19:48:05.348 Status: dzVents: > setState()
2019-09-24 19:48:05.348 Status: dzVents: > hardwareID: 21
2019-09-24 19:48:05.348 Status: dzVents: > hardwareTypeValue: 94
2019-09-24 19:48:05.348 Status: dzVents: > deviceSubType: WW
2019-09-24 19:48:05.348 Status: dzVents: > name: Tafellamp1
2019-09-24 19:48:05.348 Status: dzVents: > play()
2019-09-24 19:48:05.348 Status: dzVents: > updateRadiation()
2019-09-24 19:48:05.348 Status: dzVents: > _state: On
2019-09-24 19:48:05.348 Status: dzVents: > updateWaterflow()
2019-09-24 19:48:05.348 Status: dzVents: > _data:
2019-09-24 19:48:05.348 Status: dzVents: > description:
2019-09-24 19:48:05.348 Status: dzVents: > lastLevel: 60
2019-09-24 19:48:05.348 Status: dzVents: > rawData:
2019-09-24 19:48:05.348 Status: dzVents: > 1: 60
2019-09-24 19:48:05.348 Status: dzVents: > switchType: Dimmer
2019-09-24 19:48:05.348 Status: dzVents: > timedOut: false
2019-09-24 19:48:05.348 Status: dzVents: > deviceID: 0x14b457fffe45eb9e_light
2019-09-24 19:48:05.349 Status: dzVents: > switchTypeValue: 7
2019-09-24 19:48:05.349 Status: dzVents: > baseType: device
2019-09-24 19:48:05.349 Status: dzVents: > subType: WW
2019-09-24 19:48:05.349 Status: dzVents: > deviceType: Color Switch
2019-09-24 19:48:05.349 Status: dzVents: > batteryLevel: 255
2019-09-24 19:48:05.349 Status: dzVents: > name: Tafellamp1
2019-09-24 19:48:05.349 Status: dzVents: > data:
2019-09-24 19:48:05.349 Status: dzVents: > icon: dimmer
2019-09-24 19:48:05.349 Status: dzVents: > hardwareType: Zigbee2MQTT
2019-09-24 19:48:05.349 Status: dzVents: > levelVal: 60
2019-09-24 19:48:05.349 Status: dzVents: > maxDimLevel: 100
2019-09-24 19:48:05.349 Status: dzVents: > usedByCamera: false
2019-09-24 19:48:05.354 Status: dzVents: > _nValue: 1
2019-09-24 19:48:05.354 Status: dzVents: > hardwareTypeValue: 94
2019-09-24 19:48:05.354 Status: dzVents: > protected: false
2019-09-24 19:48:05.354 Status: dzVents: > hardwareName: Zigbee2MQTT
2019-09-24 19:48:05.354 Status: dzVents: > unit: 10
2019-09-24 19:48:05.354 Status: dzVents: > _state: On
2019-09-24 19:48:05.354 Status: dzVents: > color: {"b":0,"cw":0,"g":0,"m":2,"r":0,"t":208,"ww":0}
2019-09-24 19:48:05.354 Status: dzVents: > hardwareID: 21
2019-09-24 19:48:05.354 Status: dzVents: > changed: true
2019-09-24 19:48:05.354 Status: dzVents: > signalLevel: 1
2019-09-24 19:48:05.354 Status: dzVents: > id: 120
2019-09-24 19:48:05.354 Status: dzVents: > lastUpdate: 2019-09-24 19:48:03
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Trouble with variable of initiating device

Post by waaren »

ZatarraNL wrote: I got some new values. Is this enough?
Yes, this should be enough. Will try something later today.

Verstuurd vanaf mijn ONEPLUS A6003 met Tapatalk


Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
ZatarraNL
Posts: 28
Joined: Saturday 16 September 2017 9:02
Target OS: Linux
Domoticz version: 4.10717
Location: Netherlands
Contact:

Re: Trouble with variable of initiating device

Post by ZatarraNL »

waaren wrote: Tuesday 24 September 2019 20:02 Will try something later today.
That would be very much appreciated. Mind you, tomorrow will be more than soon enough.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Trouble with variable of initiating device

Post by waaren »

ZatarraNL wrote: Tuesday 24 September 2019 23:14 That would be very much appreciated. Mind you, tomorrow will be more than soon enough.
Can you try this ?

Code: Select all

return 
{
    on = 
    {
        devices = { 'Tafellamp1' }
    },
    
    execute = function(dz, device)
        dz.log(device.name .. ' ==>> State: ' .. device.state .. ', color: ' .. device.color , dz.LOG_INFO)
       
        local target1 = dz.devices('Tafellamp2')
        local target2 = dz.devices('Tafellamp3')
        local kelvin = dz.utils.fromJSON(device.color).t -- convert color JSON to table and use colortemperature (t)
        
        local function setKelvin(target, sourceKelvin )
            -- this function will take a deviceIDX and the color temperature (0-255) as parms 
            -- and compute corresponding level to set
            --
            local targetKelvin = math.floor(tonumber(sourceKelvin) * 100 / 255 ) -- kelvinvalues in domoticz setkelvinlevel API 0-100
            local url = dz.settings['Domoticz url'] .. '/json.htm?type=command&param=setkelvinlevel&idx=' .. target .. '&kelvin=' .. targetKelvin
            dz.openURL(url).afterSec(0.5) -- delay to prevent dimTo to overwrite just set kelvinlevels. If 0.5 is not enough just increase in steps of 0.1
        end
        
        if device.state == 'Off' then
             target1.switchOff()
             target2.switchOff()
             dz.log('tafellampen zijn uit', dz.LOG_INFO)
        elseif device.state == 'On' or device.state == 'set level' or device.state == 'set color' then
             target1.dimTo(device.level)
             target2.dimTo(device.level)
             setKelvin(target1.id, kelvin ) -- Call local defined function
             setKelvin(target2.id, kelvin )
             
            dz.log('tafellampen zijn aan', dz.LOG_INFO)
        end
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
ZatarraNL
Posts: 28
Joined: Saturday 16 September 2017 9:02
Target OS: Linux
Domoticz version: 4.10717
Location: Netherlands
Contact:

Re: Trouble with variable of initiating device

Post by ZatarraNL »

I gotta thank you a lot for going through all of this trouble.
waaren wrote: Wednesday 25 September 2019 0:52 Can you try this ?
I have tried it. It kind of works, although not completely. I will test it for a while. First impression is that the two following bulbs flicker in brightness when I change the color of the first. It takes forever for the two bulbs to copy the color. And brightness is not always correct.

Unfortunately I cannot completely follow the changes you have made. If I interpret correctly, you create a local attribute "setKelvin", of which you get the value from bulb1 via the "dz.utils.fromJSON'. After that you send the correct Kelvin value to bulb2 en bulb3 via a JSON command. In between you correct the value with some kind of formula " * 100 / 255 ". Correct?

It seems like quite a detour for a simple attribute. Does this mean that the bulb is not fully supported by the zigbee2mqtt domoticz addon?

I have no idea what should make bulb2 en bulb3 flicker. I will try to play a little with the delay of 0.5+ seconds. After a few days I will post my findings.

So far: thanks very much. Learning a lot ;)
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Trouble with variable of initiating device

Post by waaren »

ZatarraNL wrote: Wednesday 25 September 2019 20:03 Unfortunately I cannot completely follow the changes you have made. If I interpret correctly, you create a local attribute "setKelvin", of which you get the value from bulb1 via the "dz.utils.fromJSON'. After that you send the correct Kelvin value to bulb2 en bulb3 via a JSON command. In between you correct the value with some kind of formula " * 100 / 255 ". Correct?
Yes, your interpretation is correct. The setKelvin used is in fact a call to a local function.
It seems like quite a detour for a simple attribute. Does this mean that the bulb is not fully supported by the zigbee2mqtt domoticz addon?
I am not in position to comment on that. Fact is that the setKelvin method in dzVents is only implemented for RGBWW type devices. Your device seems to present itself as a WW type device. Need to discuss with the original designers of dzVents to understand if the setKelvin can be extended to this device type without introducing funny side effects. The local function I use in this script mirrors the native method used in dzVents for type RGBWW.
I have no idea what should make bulb2 en bulb3 flicker. I will try to play a little with the delay of 0.5+ seconds. After a few days I will post my findings.
I guess it's indeed the delay. On my system the delay was necessary to prevent the mix of the dimTo and API call leading to unexpected behavior.

About it being a detour. Fully agree on that and in previous situations where I implemented a kind of master / slave concept where colors and/or brightness were involved it was also like that. Implementing a scene type of approach would be much easier where you just set all lights to the same color, -kelvin and dimlevel. Having said that. Please try this script (with a slightly changed method). I tested this on a setup with Hue lights and it worked as expected but as always YMMM.

Code: Select all

return 
{
    on = 
    {
        devices = { 'Tafellamp1' }
    },
    
    execute = function(dz, master)
        
        local targetLamps = { 'Tafellamp2', 'Tafellamp3' } -- table with names of all slave-lights 
        local delay = 0
        
        local function setColorBrightness(target, color, brightness, delay )       
            local url = dz.settings['Domoticz url'] ..  '/json.htm?type=command&param=setcolbrightnessvalue' ..
                                                        '&idx=' .. target .. 
                                                        '&color=' .. dz.utils.urlEncode(color)  ..
                                                        '&brightness=' .. brightness
            dz.openURL(url).afterSec(delay or 0)
        end
        
        for _, target in ipairs(targetLamps) do -- loop through table with names of all slave-lights
            if master.state == 'Off' then
                dz.devices(target).switchOff()   -- target is a name of a slave light
            elseif master.state == 'On' or master.state == 'Set level' or master.state == 'Set Color' then
                delay = delay + 0.1 -- Prevent too quick firing of openURL calls
                setColorBrightness(dz.devices(target).id, master.color, master.level, delay ) -- call local function to set all color attributes and brightness
                -- dz.devices(target).switchOn().silent() -- Uncomment when lights do no turn on after setting the color
            end
            dz.log(target .. ' followed the leader..', dz.LOG_INFO)
        end
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
ZatarraNL
Posts: 28
Joined: Saturday 16 September 2017 9:02
Target OS: Linux
Domoticz version: 4.10717
Location: Netherlands
Contact:

Re: Trouble with variable of initiating device

Post by ZatarraNL »

I had some trouble with the script. When changing the temperature of the light, bulb 2 and 3 started to flicker. As you said this was to be solved with the delay. 0.7 seconds worked for me. But another problem occurred: When changing only the brightness, bulb2 and bulb3 changed back to their original brightness. Probably caused by the switching of the temperature. So I switched the order in which both were handled. This kind-of solved everything, as well as eliminated the need for the delay. The code works as follows:

Code: Select all

return 
{
    on = 
    {
        devices = { 'Tafellamp1' }
    },
    
    execute = function(dz, device)
        dz.log(device.name .. ' ==>> State: ' .. device.state .. ', color: ' .. device.color , dz.LOG_INFO)
       
        local target1 = dz.devices('Tafellamp2')
        local target2 = dz.devices('Tafellamp3')
        local kelvin = dz.utils.fromJSON(device.color).t -- convert color JSON to table and use colortemperature (t)
        
        local function setKelvin(target, sourceKelvin )
            -- this function will take a deviceIDX and the color temperature (0-255) as parms 
            -- and compute corresponding level to set
            --
            local targetKelvin = math.floor(tonumber(sourceKelvin) * 100 / 255 ) -- kelvinvalues in domoticz setkelvinlevel API 0-100
            local url = dz.settings['Domoticz url'] .. '/json.htm?type=command&param=setkelvinlevel&idx=' .. target .. '&kelvin=' .. targetKelvin
            dz.openURL(url) --.afterSec(0.7) -- delay to prevent dimTo to overwrite just set kelvinlevels. If 0.5 is not enough just increase in steps of 0.1
        end
        
        if device.state == 'Off' then
             target1.switchOff()
             target2.switchOff()
             dz.log('tafellampen zijn uit', dz.LOG_INFO)
        elseif device.state == 'On' or device.state == 'set level' or device.state == 'set color' then
             setKelvin(target1.id, kelvin ) -- Call local defined function
             setKelvin(target2.id, kelvin )
             target1.dimTo(device.level)
             target2.dimTo(device.level)
             
            dz.log('tafellampen zijn aan', dz.LOG_INFO)
        end
    end
}
So thanks very much. This problem is solved. On to the next problem (when starting zigbee2mqtt with dzVents, I rather took a lot of hay on my fork ;))
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Trouble with variable of initiating device

Post by waaren »

ZatarraNL wrote: Friday 27 September 2019 11:45 So thanks very much. This problem is solved. On to the next problem (when starting zigbee2mqtt with dzVents, I rather took a lot of hay on my fork ;))
Good to read that you were able to solve it. I would very much appreciate it if you could also test the latest script I posted in this topic with the slightly different approach. The results of this test will help to improve dzVents in this area.

Thanks for your time.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
ZatarraNL
Posts: 28
Joined: Saturday 16 September 2017 9:02
Target OS: Linux
Domoticz version: 4.10717
Location: Netherlands
Contact:

Re: Trouble with variable of initiating device

Post by ZatarraNL »

waaren wrote: Friday 27 September 2019 21:20 I would very much appreciate it if you could also test the latest script I posted in this topic with the slightly different approach. The results of this test will help to improve dzVents in this area.
Here the results of the tests:
- All the variables work: on/off, brightness, temperature
- On/of reacts very quickly. Nice.
- Brightness reacts very quickly. Nice too.
- Temperature is more complicated. When I change the temperature of bulb1, it always returns to cold, after which the temperature warms up in little steps. After it reaches the set temperature, bulb2 en bulb3 simultaneously repeat the proces. The result is: the cold temperature is reached quickly by all three bulbs, after which the 3 bulbs don't react on any command for a few seconds. The warm temperature takes a very long time. But when done, I can immediately send another command.

Conclusion: this script works better than the previous.

I hope this gives some insight.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Trouble with variable of initiating device  [Solved]

Post by waaren »

ZatarraNL wrote: Sunday 06 October 2019 21:15 Here the results of the tests:
- All the variables work: on/off, brightness, temperature
- On/of reacts very quickly. Nice.
- Brightness reacts very quickly. Nice too.
- Temperature is more complicated. When I change the temperature of bulb1, it always returns to cold, after which the temperature warms up in little steps. After it reaches the set temperature, bulb2 en bulb3 simultaneously repeat the proces. The result is: the cold temperature is reached quickly by all three bulbs, after which the 3 bulbs don't react on any command for a few seconds. The warm temperature takes a very long time. But when done, I can immediately send another command.
👍👍Thx for testing, I will include it in one of the next releases of dzVents for this type of devices
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dheuts
Posts: 65
Joined: Monday 25 March 2019 15:14
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Brunssum, Netherlands
Contact:

Re: Trouble with variable of initiating device

Post by dheuts »

ZatarraNL wrote: Sunday 06 October 2019 21:15
waaren wrote: Friday 27 September 2019 21:20 I would very much appreciate it if you could also test the latest script I posted in this topic with the slightly different approach. The results of this test will help to improve dzVents in this area.
Here the results of the tests:
- All the variables work: on/off, brightness, temperature
- On/of reacts very quickly. Nice.
- Brightness reacts very quickly. Nice too.
- Temperature is more complicated. When I change the temperature of bulb1, it always returns to cold, after which the temperature warms up in little steps. After it reaches the set temperature, bulb2 en bulb3 simultaneously repeat the proces. The result is: the cold temperature is reached quickly by all three bulbs, after which the 3 bulbs don't react on any command for a few seconds. The warm temperature takes a very long time. But when done, I can immediately send another command.

Conclusion: this script works better than the previous.

I hope this gives some insight.
Working great, thanks!
Raspberry Pi 4 With Domoticz - RFXCom - Tuya Wifi LED lights - Chuango Alarm - Zwave+ - Zigbee2MQTT - Anna Thermostat - Broadlink IR, P1 - Eufy Robo Vacuum - Worx Robo Mower
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest