Determine what initiated a device change? (or updateSetPoint(value).silent())

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

Moderator: leecollings

Post Reply
thibaut
Posts: 3
Joined: Monday 04 December 2017 18:25
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Determine what initiated a device change? (or updateSetPoint(value).silent())

Post by thibaut »

Hi,

I have a battery-powered z-wave thermostat (SRT 323) that I sometimes control from scripts when e.g. temperature in another room is getting too low.

Whenever I change the setpoint from a script, that triggers two events:
- one immediately after I change the setpoint, when my command is queued in domoticz (or so I guess) ;
- another one when the device wakes up and actually receives the new set point.

Now I want to react to setpoint changes, but only when initiated by the user (by moving the physical dial on the device). So I want to filter out the events triggered by a script. How can I do that?

I have tried to append .silent() to the command in the script, but that doesn't seem to be supported for updateSetPoint() (I'm under domoticz 3.8153):

Code: Select all

mydevice.updateSetPoint(value).silent()
yields an error:
2017-12-07 15:16:00.566 Error: dzVents: Error: An error occured when calling event handler test
2017-12-07 15:16:00.566 Error: dzVents: Error: .../domoticz/var/scripts/dzVents/generated_scripts/test.lua:30: attempt to index a nil value
I addition, I guess that the silent() feature would only prevent the first of the two script-generated events, but not the second (which I guess is actually generated by the device when it receives the new setpoint).

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

Re: Determine what initiated a device change? (or updateSetPoint(value).silent())

Post by dannybloe »

In the upcoming dzVents 2.4 you can use silent() with updateSetPoint(). In the mean-time you may use persistent variables to set flags in you script to indicate if it was a user action or something else. See the documentation.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
Doler
Posts: 142
Joined: Friday 31 July 2015 21:02
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Sint-Oedenrode, Netherlands
Contact:

Re: Determine what initiated a device change? (or updateSetPoint(value).silent())

Post by Doler »

dannybloe wrote: Wednesday 03 January 2018 10:28 In the upcoming dzVents 2.4 you can use silent() with updateSetPoint(). In the mean-time you may use persistent variables to set flags in you script to indicate if it was a user action or something else. See the documentation.
Could you confirm that this works because it doesn't work for me:

Code: Select all

return {
	active = true,
	on = {
		timer = { TIME_INTERVAL },
		devices = { c.AC_MODE, c.AC_FANSPEED, c.AC_TEMPERATURE }
	},
		logging = {
			level = LOG_LEVEL,
			marker = LOG_MARKER
	},
	execute = function(dz, item, triggerInfo)

		if item.isTimer then
			-- Update thermostat every hour to avoid red bar
			local thermostat = dz.devices(c.AC_TEMPERATURE)
			thermostat.updateSetPoint(thermostat.setPoint).silent()
		else
			-- Respond to changed AC setting
			.....
The script then gets a device change from thermostat:
Spoiler: show
2018-02-25 21:00:00.316 dzVents: Info: airco v1.0: ------ Start external script: airco.lua:, trigger: every hour
2018-02-25 21:00:00.334 dzVents: Info: airco v1.0: ------ Finished airco.lua
2018-02-25 21:00:01.003 (DummyHW) Thermostat (AC Temperature)
2018-02-25 21:00:01.331 dzVents: Info: airco v1.0: ------ Start external script: airco.lua: Device: "AC Temperature (DummyHW)", Index: 56
2018-02-25 21:00:01.335 dzVents: Info: airco v1.0: Mode: 2, Fanspeed: 0, Temperature: 21, Power: 1
2018-02-25 21:00:01.335 dzVents: Info: airco v1.0: IR Command: 00012015
2018-02-25 21:00:01.335 dzVents: Info: airco v1.0: ------ Finished airco.lua
Can't see that I'm doing something wrong.
Thanks, Mark
Mark: Domoticz Beta on Raspberry Pi 4 running Debian Bookworm - Z-Stick 7 - RFXCom - P1 - MySensors - SolarEdge - Dahua - Philips Hue - Docker - Zigbee2mqtt (plugin) - Zwave-js-ui - dzVents - Nodered
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Determine what initiated a device change? (or updateSetPoint(value).silent())

Post by waaren »

Doler wrote: Sunday 25 February 2018 20:29
dannybloe wrote: Wednesday 03 January 2018 10:28 In the upcoming dzVents 2.4 you can use silent() with updateSetPoint(). In the mean-time you may use persistent variables to set flags in you script to indicate if it was a user action or something else. See the documentation.
Could you confirm that this works because it doesn't work for me:

Code: Select all

return {
	active = true,
	on = {
		timer = { TIME_INTERVAL },
		devices = { c.AC_MODE, c.AC_FANSPEED, c.AC_TEMPERATURE }
	},
		logging = {
			level = LOG_LEVEL,
			marker = LOG_MARKER
	},
	execute = function(dz, item, triggerInfo)

		if item.isTimer then
			-- Update thermostat every hour to avoid red bar
			local thermostat = dz.devices(c.AC_TEMPERATURE)
			thermostat.updateSetPoint(thermostat.setPoint).silent()
		else
			-- Respond to changed AC setting
			.....
The script then gets a device change from thermostat:
Spoiler: show
2018-02-25 21:00:00.316 dzVents: Info: airco v1.0: ------ Start external script: airco.lua:, trigger: every hour
2018-02-25 21:00:00.334 dzVents: Info: airco v1.0: ------ Finished airco.lua
2018-02-25 21:00:01.003 (DummyHW) Thermostat (AC Temperature)
2018-02-25 21:00:01.331 dzVents: Info: airco v1.0: ------ Start external script: airco.lua: Device: "AC Temperature (DummyHW)", Index: 56
2018-02-25 21:00:01.335 dzVents: Info: airco v1.0: Mode: 2, Fanspeed: 0, Temperature: 21, Power: 1
2018-02-25 21:00:01.335 dzVents: Info: airco v1.0: IR Command: 00012015
2018-02-25 21:00:01.335 dzVents: Info: airco v1.0: ------ Finished airco.lua
Can't see that I'm doing something wrong.
Thanks, Mark
can you confirm
that thermostat.setPoint is a number at the line thermostat.updateSetPoint(thermostat.setPoint).silent() ?

eg by print ("thermostat.setPoint is now : " .. tostring(thermostat.setPoint))
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Doler
Posts: 142
Joined: Friday 31 July 2015 21:02
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Sint-Oedenrode, Netherlands
Contact:

Re: Determine what initiated a device change? (or updateSetPoint(value).silent())

Post by Doler »

waaren wrote: Sunday 25 February 2018 22:11 can you confirm
that thermostat.setPoint is a number at the line thermostat.updateSetPoint(thermostat.setPoint).silent() ?

eg by print ("thermostat.setPoint is now : " .. tostring(thermostat.setPoint))
First line added returns 'number', second line returns '21'. So yes, it is a number.

Code: Select all

		if item.isTimer then
			-- Update thermostat every hour to avoid red bar
			local thermostat = dz.devices(c.AC_TEMPERATURE)
		print(type(thermostat.setPoint))
		print ("thermostat.setPoint is now : " .. tostring(thermostat.setPoint))
			thermostat.updateSetPoint(thermostat.setPoint).silent()
BTW. The thermostat device is a virtual device, maybe that makes the difference?
Mark
Mark: Domoticz Beta on Raspberry Pi 4 running Debian Bookworm - Z-Stick 7 - RFXCom - P1 - MySensors - SolarEdge - Dahua - Philips Hue - Docker - Zigbee2mqtt (plugin) - Zwave-js-ui - dzVents - Nodered
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Determine what initiated a device change? (or updateSetPoint(value).silent())

Post by waaren »

Doler wrote: Sunday 25 February 2018 23:05
waaren wrote: Sunday 25 February 2018 22:11 can you confirm
that thermostat.setPoint is a number at the line thermostat.updateSetPoint(thermostat.setPoint).silent() ?

eg by print ("thermostat.setPoint is now : " .. tostring(thermostat.setPoint))
First line added returns 'number', second line returns '21'. So yes, it is a number.

Code: Select all

		if item.isTimer then
			-- Update thermostat every hour to avoid red bar
			local thermostat = dz.devices(c.AC_TEMPERATURE)
		print(type(thermostat.setPoint))
		print ("thermostat.setPoint is now : " .. tostring(thermostat.setPoint))
			thermostat.updateSetPoint(thermostat.setPoint).silent()
BTW. The thermostat device is a virtual device, maybe that makes the difference?
Mark
maybe it's the wrong type for the updateSetpoint method. Can you post the output of thermostat.dump() ?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Doler
Posts: 142
Joined: Friday 31 July 2015 21:02
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Sint-Oedenrode, Netherlands
Contact:

Re: Determine what initiated a device change? (or updateSetPoint(value).silent())

Post by Doler »

waaren wrote: Sunday 25 February 2018 23:35
Doler wrote: Sunday 25 February 2018 23:05
waaren wrote: Sunday 25 February 2018 22:11 can you confirm
that thermostat.setPoint is a number at the line thermostat.updateSetPoint(thermostat.setPoint).silent() ?

eg by print ("thermostat.setPoint is now : " .. tostring(thermostat.setPoint))
First line added returns 'number', second line returns '21'. So yes, it is a number.

Code: Select all

		if item.isTimer then
			-- Update thermostat every hour to avoid red bar
			local thermostat = dz.devices(c.AC_TEMPERATURE)
		print(type(thermostat.setPoint))
		print ("thermostat.setPoint is now : " .. tostring(thermostat.setPoint))
			thermostat.updateSetPoint(thermostat.setPoint).silent()
BTW. The thermostat device is a virtual device, maybe that makes the difference?
Mark
maybe it's the wrong type for the updateSetpoint method. Can you post the output of thermostat.dump() ?
Here is the dump:
Spoiler: show
2018-02-26 08:49:00.602 dzVents: > updateHumidity()
2018-02-26 08:49:00.602 dzVents: > name: AC Temperature
2018-02-26 08:49:00.602 dzVents: > lastUpdate:
2018-02-26 08:49:00.602 dzVents: > hoursAgo: 0
2018-02-26 08:49:00.602 dzVents: > ruleMatchesTimeRange()
2018-02-26 08:49:00.603 dzVents: > ruleIsAtSunset()
2018-02-26 08:49:00.603 dzVents: > ruleIsAtSunrise()
2018-02-26 08:49:00.603 dzVents: > ruleIsOnDay()
2018-02-26 08:49:00.603 dzVents: > ruleIsOnDate()
2018-02-26 08:49:00.603 dzVents: > yday: 57
2018-02-26 08:49:00.603 dzVents: > isdst: false
2018-02-26 08:49:00.603 dzVents: > wday: 2
2018-02-26 08:49:00.603 dzVents: > sec: 1
2018-02-26 08:49:00.603 dzVents: > utils:
2018-02-26 08:49:00.603 dzVents: > LOG_MODULE_EXEC_INFO: 2
2018-02-26 08:49:00.603 dzVents: > fileExists()
2018-02-26 08:49:00.603 dzVents: > toJSON()
2018-02-26 08:49:00.603 dzVents: > LOG_ERROR: 1
2018-02-26 08:49:00.603 dzVents: > log()
2018-02-26 08:49:00.603 dzVents: > LOG_FORCE: 0.5
2018-02-26 08:49:00.603 dzVents: > osExecute()
2018-02-26 08:49:00.603 dzVents: > urlEncode()
2018-02-26 08:49:00.603 dzVents: > rgbToHSB()
2018-02-26 08:49:00.603 dzVents: > LOG_INFO: 3
2018-02-26 08:49:00.603 dzVents: > fromJSON()
2018-02-26 08:49:00.603 dzVents: > print()
2018-02-26 08:49:00.603 dzVents: > LOG_DEBUG: 4
2018-02-26 08:49:00.603 dzVents: > year: 2018
2018-02-26 08:49:00.604 dzVents: > ruleIsAtDayTime()
2018-02-26 08:49:00.604 dzVents: > matchesRule()
2018-02-26 08:49:00.604 dzVents: > ruleMatchesBetweenRange()
2018-02-26 08:49:00.604 dzVents: > milliSeconds: 0
2018-02-26 08:49:00.604 dzVents: > dDate: 1519628401
2018-02-26 08:49:00.604 dzVents: > getISO()
2018-02-26 08:49:00.604 dzVents: > ruleMatchesTime()
2018-02-26 08:49:00.604 dzVents: > isToday: true
2018-02-26 08:49:00.604 dzVents: > current:
2018-02-26 08:49:00.604 dzVents: > month: 2
2018-02-26 08:49:00.604 dzVents: > yday: 57
2018-02-26 08:49:00.604 dzVents: > isdst: false
2018-02-26 08:49:00.604 dzVents: > wday: 2
2018-02-26 08:49:00.604 dzVents: > sec: 0
2018-02-26 08:49:00.604 dzVents: > day: 26
2018-02-26 08:49:00.604 dzVents: > min: 49
2018-02-26 08:49:00.604 dzVents: > year: 2018
2018-02-26 08:49:00.604 dzVents: > hour: 8
2018-02-26 08:49:00.604 dzVents: > ruleMatchesMinuteSpecification()
2018-02-26 08:49:00.604 dzVents: > ruleIsAtNight()
2018-02-26 08:49:00.604 dzVents: > secondsSinceMidnight: 28801
2018-02-26 08:49:00.604 dzVents: > hour: 8
2018-02-26 08:49:00.604 dzVents: > rawDate: 2018-2-26
2018-02-26 08:49:00.605 dzVents: > ruleIsBeforeSunset()
2018-02-26 08:49:00.605 dzVents: > ruleIsAfterSunset()
2018-02-26 08:49:00.605 dzVents: > daysAgo: 0
2018-02-26 08:49:00.605 dzVents: > millisecondsAgo: 2939482
2018-02-26 08:49:00.605 dzVents: > msAgo: 2939482
2018-02-26 08:49:00.605 dzVents: > isUTC: false
2018-02-26 08:49:00.605 dzVents: > ruleIsInWeek()
2018-02-26 08:49:00.605 dzVents: > month: 2
2018-02-26 08:49:00.605 dzVents: > rawTime: 8:0:1
2018-02-26 08:49:00.605 dzVents: > ruleIsAfterSunrise()
2018-02-26 08:49:00.605 dzVents: > ruleIsBeforeSunrise()
2018-02-26 08:49:00.605 dzVents: > seconds: 1
2018-02-26 08:49:00.605 dzVents: > compare()
2018-02-26 08:49:00.605 dzVents: > ruleMatchesHourSpecification()
2018-02-26 08:49:00.605 dzVents: > milliseconds: 0
2018-02-26 08:49:00.605 dzVents: > min: 0
2018-02-26 08:49:00.605 dzVents: > day: 26
2018-02-26 08:49:00.605 dzVents: > dayAbbrOfWeek: mon
2018-02-26 08:49:00.605 dzVents: > minutes: 0
2018-02-26 08:49:00.605 dzVents: > week: 9
2018-02-26 08:49:00.605 dzVents: > raw: 2018-02-26 08:00:01
2018-02-26 08:49:00.605 dzVents: > secondsAgo: 2939
2018-02-26 08:49:00.605 dzVents: > minutesAgo: 48
2018-02-26 08:49:00.606 dzVents: > isScene: false
2018-02-26 08:49:00.606 dzVents: > deviceSubType: SetPoint
2018-02-26 08:49:00.606 dzVents: > setWhiteMode()
2018-02-26 08:49:00.606 dzVents: > updateTemperature()
2018-02-26 08:49:00.606 dzVents: > toggleSwitch()
2018-02-26 08:49:00.606 dzVents: > pause()
2018-02-26 08:49:00.606 dzVents: > updateAlertSensor()
2018-02-26 08:49:00.606 dzVents: > onkyoEISCPCommand()
2018-02-26 08:49:00.606 dzVents: > hardwareID: 4
2018-02-26 08:49:00.606 dzVents: > setState()
2018-02-26 08:49:00.606 dzVents: > kodiPause()
2018-02-26 08:49:00.606 dzVents: > isTimer: false
2018-02-26 08:49:00.606 dzVents: > updateWaterflow()
2018-02-26 08:49:00.606 dzVents: > updateMode()
2018-02-26 08:49:00.606 dzVents: > hardwareId: 4
2018-02-26 08:49:00.606 dzVents: > hardwareName: DummyHW
2018-02-26 08:49:00.606 dzVents: > dump()
2018-02-26 08:49:00.606 dzVents: > rawData:
2018-02-26 08:49:00.606 dzVents: > 1: 21.00
2018-02-26 08:49:00.606 dzVents: > isVariable: false
Mark
Mark: Domoticz Beta on Raspberry Pi 4 running Debian Bookworm - Z-Stick 7 - RFXCom - P1 - MySensors - SolarEdge - Dahua - Philips Hue - Docker - Zigbee2mqtt (plugin) - Zwave-js-ui - dzVents - Nodered
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Determine what initiated a device change? (or updateSetPoint(value).silent())

Post by waaren »

@Mark, I don't see a value for hardwareTypeValue and that could well be related to the fact that it is a virtual device. Not sure if this affects the logic in the dzVents device-adapter thermostat_setpoint_device.lua
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Post Reply

Who is online

Users browsing this forum: TiXav and 0 guests