script showing weird messages

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

Moderator: leecollings

Post Reply
ricorico94
Posts: 94
Joined: Monday 26 October 2015 10:41
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

script showing weird messages

Post by ricorico94 »

Hi,
I wrote a script to manage a heater. The script works but I don't understand the logs which don't seem consistent with what script does.
Context: I have a heater managed by zwave device that is registered in domoticz as a Dimmer device ('Rad_SdB') (value <10 means heater is Off, value >=50 means heater is full On). I had created separate dummy devices to manage temporary heating (ie dummy device is of switch type and I set it so that it turns off after XXX seconds after switch on. I can command this dummy devices (such as 'serviettes_SdB') through my google home, using the google plugin, and the script is then modifying the value of Dimmer linked to heater.

Script:

Code: Select all

return {
	on = {
		devices = {
			
			'Serviettes_SdB'
		}
	},
	logging = {
		level = domoticz.LOG_INFO,
		marker = 'script SdB',
	},
	execute = function(dz, device)
		dz.log('Device ' .. device.name .. ' was changed and Rad_Sdb currently at '.. dz.devices('Rad_SdB').level .. ' and switch at ' .. device.state, dz.LOG_INFO)
		if (device.name=='Serviettes_SdB' and device.state=='On') then
		        dz.log('Rad_SdB initially set to '..dz.devices('Rad_SdB').level, dz.LOG_INFO)
		        dz.devices('Rad_SdB').dimTo(60)
		        dz.log('Rad_SdB now set to '..dz.devices('Rad_SdB').level, dz.LOG_INFO)
		        
		end
		if (device.name=='Serviettes_SdB' and (device.state=='Off') ) then
		        dz.log('Rad_SdB initially set to '..dz.devices('Rad_SdB').level, dz.LOG_INFO)
		        dz.devices('Rad_SdB').dimTo(1)
		        dz.log('Rad_SdB set to '..dz.devices('Rad_SdB').level, dz.LOG_INFO)
		end
	end
}
Here's the log when I switch on the dummy switch:
2024-03-10 21:33:29.810 Serviettes_SdB: Light/Switch (Serviettes_SdB)
2024-03-10 21:33:29.975 Zstick Gen5: Domoticz has send a Switch command!, Level: 60, NodeID: 31 (0x1f)
2024-03-10 21:33:29.983 Zstick Gen5: Light/Switch (Rad_SdB)
2024-03-10 21:33:29.788 Status: User: eric (IP: 192.168.0.254) initiated a switch command (2604/Serviettes_SdB/On)
2024-03-10 21:33:29.931 Status: dzVents: Info: Handling events for: "Serviettes_SdB", value: "On"
2024-03-10 21:33:29.931 Status: dzVents: Info: script SdB: ------ Start internal script: Radiateur_SdB: Device: "Serviettes_SdB (Serviettes_SdB)", Index: 2604
2024-03-10 21:33:29.932 Status: dzVents: Info: script SdB: Device Serviettes_SdB was changed and Rad_Sdb currently at 1 and switch at On
2024-03-10 21:33:29.932 Status: dzVents: Info: script SdB: Rad_SdB initially set to 1
2024-03-10 21:33:29.933 Status: dzVents: Info: script SdB: Rad_SdB now set to 1
2024-03-10 21:33:29.933 Status: dzVents: Info: script SdB: ------ Finished Radiateur_SdB
2024-03-10 21:33:29.935 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
and the logs when switching off:
2024-03-10 21:36:09.970 Serviettes_SdB: Light/Switch (Serviettes_SdB)
2024-03-10 21:36:09.955 Status: User: eric (IP: 192.168.0.254) initiated a switch command (2604/Serviettes_SdB/Off)
2024-03-10 21:36:10.114 Zstick Gen5: Domoticz has send a Switch command!, Level: 1, NodeID: 31 (0x1f)
2024-03-10 21:36:10.122 Zstick Gen5: Light/Switch (Rad_SdB)
2024-03-10 21:36:10.088 Status: dzVents: Info: Handling events for: "Serviettes_SdB", value: "Off"
2024-03-10 21:36:10.089 Status: dzVents: Info: script SdB: ------ Start internal script: Radiateur_SdB: Device: "Serviettes_SdB (Serviettes_SdB)", Index: 2604
2024-03-10 21:36:10.090 Status: dzVents: Info: script SdB: Device Serviettes_SdB was changed and Rad_Sdb currently at 60 and switch at Off
2024-03-10 21:36:10.090 Status: dzVents: Info: script SdB: Rad_SdB initially set to 60
2024-03-10 21:36:10.090 Status: dzVents: Info: script SdB: Rad_SdB set to 60
2024-03-10 21:36:10.090 Status: dzVents: Info: script SdB: ------ Finished Radiateur_SdB
As you can see, the proper command is sent to the heater dimmer device (2d row above when switching on, set to 60 level), but the logs show wrong values ("1"): I would expect to read "initially set to 1" and "now set to 60" when switching on). Same issue (in opposite way) when switching off.

I probably don't understand something here.. Anyone could help me ?

note: I use domoticz v2023.2 on Raspbian
br,
Ricorico94
User avatar
waltervl
Posts: 5855
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: script showing weird messages

Post by waltervl »

In Domoticz status updates are not real time updated for levels. So you have to trigger the script again to get the real value.

But in the end it works does it? Your devices react correctly to the commands dimto(1) and dimto(60)?
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
User avatar
habahabahaba
Posts: 233
Joined: Saturday 18 March 2023 14:44
Target OS: Windows
Domoticz version: 2024.4
Contact:

Re: script showing weird messages

Post by habahabahaba »

My guess.

Writing to the database occurs only after the script is executed, so as not to access it too often, avoid possible damage and speed up the execution of scripts.
Kedi
Posts: 575
Joined: Monday 20 March 2023 14:41
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Somewhere in NL
Contact:

Re: script showing weird messages

Post by Kedi »

Inside the script the 'dz.devices('Rad_SdB').level' does NOT change.
If you want to see the change in effect the you can use a customtrigger and call the script again.
The second time the script is called (in a few milliseconds) the changes should be present.
But is quite a lot of scripting to show what you already know e.g. setting the level to another setting.
I suppose that you don't monitor the logfile all the time in real time. ;)
Logic will get you from A to B. Imagination will take you everywhere.
ricorico94
Posts: 94
Joined: Monday 26 October 2015 10:41
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: script showing weird messages

Post by ricorico94 »

Hi,
Thanks a lot for your clarifications.
I had inserted such logs to introduce some kind of checking, mainly for debugging. I was intending to check that a change had been effectively applied. I now understand I can't use such approach for the script to check that the change was applied and I'll modify my script.
Thanks again !
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests