Is the washing machine done?
Moderator: leecollings
-
- Posts: 2
- Joined: Sunday 08 September 2019 6:49
- Target OS: Linux
- Domoticz version:
- Contact:
Re: Is the washing machine done?
I will look into it and let you know after a while.
-
- Posts: 59
- Joined: Sunday 28 July 2019 22:59
- Target OS: NAS (Synology & others)
- Domoticz version:
- Contact:
Re: Is the washing machine done?
I have been struggling to get a text sensor to be updated with the information on the status of the washmachine. I know many of you have a notification set up, but I would like to have a switch or text sensor to be updated. That way, anyone looking at the dashboard can see the wash is done (and hopefully, people will put it in the dryer voluntarily
I've tried several pieces of code. For instance:
I inserted this code after the line where this message is printed to the log.
Does anyone have an example how I can fix this? Can some of you share your final script so I can see and learn from them?
I've tried several pieces of code. For instance:
Code: Select all
local StatusWasmachine
domoticz.StatusWasmachine.updateText('wasmachine is klaar')
Does anyone have an example how I can fix this? Can some of you share your final script so I can see and learn from them?
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Is the washing machine done?
Change the lines tojaaap wrote: ↑Sunday 29 September 2019 14:57 I have been struggling to get a text sensor to be updated with the information on the status of the washmachine. I know many of you have a notification set up, but I would like to have a switch or text sensor to be updated. That way, anyone looking at the dashboard can see the wash is done (and hopefully, people will put it in the dryer voluntarily
Code: Select all
local StatusWasmachine = domoticz.devices('name of your text sensor')
StatusWasmachine.updateText('wasmachine is klaar')
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 59
- Joined: Sunday 28 July 2019 22:59
- Target OS: NAS (Synology & others)
- Domoticz version:
- Contact:
Re: Is the washing machine done?
Hi waaren,
Thank you for your suggestion. However, I keep getting the same respons in the log:
The full script I'm using is:
Thanks in advance for helping out!
EDIT: it works! (I knew it would, since it was coming from waaren
I found out that one should place code that calls on devices (such as 'local StatusWasmachine = domoticz.devices('Status wasmachine')' after the 'execute = function' and that you should be afware of capitals and lowercase lettering... (my bad... )
Thanks waaren, you're golden!
Thank you for your suggestion. However, I keep getting the same respons in the log:
Code: Select all
2019-09-30 00:04:26.606 Status: dzVents: Error (2.4.19): .../scripts/dzVents/generated_scripts/is de was klaar 2.lua:25: attempt to call field 'devices' (a nil value)
Code: Select all
-- create a lookup table that matches a usage
-- device to the accompanying switch
local USAGE_DEVICES = {
-- ['SC-Wasdroger verbruik'] = 'Wasdroger', -- You need to have a inline wall plug that measures energy,
['SC-Wasmachine verbruik'] = 'Wasmachine', -- here you make the link between the energy device and the wall plug.
}
local USAGE_SwitchTimeOutMinutes = {
-- ['Wasdroger'] = 6, -- Here you define how long no power is used per device.
['Wasmachine'] = 6, -- The period is in minutes. Adjust to your needs. Between every add a ",".
}
local USAGE_MaxWatt = {
-- ['Wasdroger'] = 3, -- Here you define the maximum amount of power a device uses when it is in standby.
['Wasmachine'] = 1, -- Some devices uses a little amount of power. Test it and a slightly higher usage.
}
local USAGE_Notify = {
-- ['Wasdroger'] = 'Yes', -- In some cases you want to be notified when a device is turned on and off.
['Wasmachine'] = 'Yes', -- Adjust to your needs. Between every line you need to add a ",".
}
local StatusWasmachine = domoticz.devices('Status wasmachine')
return {
logging = {
level = domoticz.LOG_INFO, -- Uncomment to override the dzVents global logging setting
marker = 'POW'
},
on = {
timer = { 'every 5 minutes' },
devices = { -- Make sure that the devices are the same as above
-- 'SC-Wasdroger verbruik',
'SC-Wasmachine verbruik',
},
},
data = { -- use exact device names to match USAGE_DEVICES
-- ['SC-Wasdroger verbruik'] = { history = true, maxMinutes = 10 },
['SC-Wasmachine verbruik'] = { history = true, maxMinutes = 10 } --deze weer op 10 zetten straks
},
execute = function(domoticz, device)
if (device.isTimer) then
-- we need to check for expiration of grace period
domoticz.log("timer trigger")
for i, machine in pairs(USAGE_DEVICES) do
local usage = "SC-" .. machine.. " verbruik"
domoticz.log("device = " .. machine)
local actual = domoticz.devices(usage).WhActual
local average = domoticz.data[usage].avg()
domoticz.data[usage].add(actual)
domoticz.log("actual = " .. actual)
domoticz.log("average = " .. tostring(average))
if actual == 0 then
domoticz.log(machine .. " gebruikt geen energie, dus is uit")
domoticz.devices(machine).switchOff().checkFirst()
StatusWasmachine.updateText('wasmachine is uit')
elseif actual < USAGE_MaxWatt[machine] then
domoticz.log(machine .. " gebruikt weinig energie, is de machine klaar?")
StatusWasmachine.updateText('Wasmachine is klaar')
local timeout = USAGE_SwitchTimeOutMinutes[machine]
domoticz.log(machine .. " gebruikte gemiddeld: " .. tostring(domoticz.data[usage].avg))
if (average <= USAGE_MaxWatt[machine]) then
domoticz.log(machine .. " lijkt standby te staan, we nemen aan klaar.")
domoticz.devices(machine).switchOff().checkFirst()
domoticz.data[usage].reset()
else
domoticz.log(machine .. " maar nog te kort om klaar te zijn.")
domoticz.devices(machine).switchOn().checkFirst()
end
else
domoticz.log(machine .. " gebruikt energie, dus is (nog) bezig.")
domoticz.devices(machine).switchOn().checkFirst()
end
end
elseif (USAGE_DEVICES[device.name] ~= nil) then
-- we have a usage sensor here
domoticz.log("usage trigger")
local switch = domoticz.devices(USAGE_DEVICES[device.name])
local timeout = USAGE_SwitchTimeOutMinutes[USAGE_DEVICES[device.name]]
local watt = USAGE_MaxWatt[USAGE_DEVICES[device.name]]
domoticz.data[device.name].add(device.WhActual)
local history = domoticz.data[device.name]
domoticz.log("device = " .. device.name)
if (switch.active) then
domoticz.log("Switch is active, check average use and last update")
domoticz.log("usage last update: " .. tostring(switch.lastUpdate.minutesAgo))
domoticz.log("usage = " .. tostring(device.WhActual))
domoticz.log("average = " .. tostring(history.avg()))
if (history.avg() <= watt and device.WhActual <= watt and switch.lastUpdate.minutesAgo >= timeout) then
switch.switchOff().checkFirst()
domoticz.log("Turn switch off")
domoticz.data[device.name].reset()
end
else
domoticz.log("Switch not on")
if (device.WhActual > watt) then
domoticz.log("but power use is over treshold, turn switch on")
switch.switchOn().checkFirst()
end
end
end
end
}
EDIT: it works! (I knew it would, since it was coming from waaren
I found out that one should place code that calls on devices (such as 'local StatusWasmachine = domoticz.devices('Status wasmachine')' after the 'execute = function' and that you should be afware of capitals and lowercase lettering... (my bad... )
Thanks waaren, you're golden!
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Is the washing machine done?
I understand that it is bit confusing in this script. That's why I am not a big fan of declaring a lot of variables before the "execute =" blockjaaap wrote: ↑Monday 30 September 2019 0:06 Thank you for your suggestion. However, I keep getting the same respons in the log:Code: Select all
2019-09-30 00:04:26.606 Status: dzVents: Error (2.4.19): .../scripts/dzVents/generated_scripts/is de was klaar 2.lua:25: attempt to call field 'devices' (a nil value)
at line 25 there is no domoticz object known to the script yet as it passed to execute block (at line 45) so you cannot refer to any of the attributes in it either.
If you move this line 25 to the line directly after the current line 45 you will not see this error. (have not checked anything else)
[EDIT] Good that you found it !!
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
- gjaa
- Posts: 38
- Joined: Thursday 12 February 2015 6:59
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Location: The Netherlands
- Contact:
Re: Is the washing machine done?
Thanks for the script
I use it for the computers of the kids
But the next step is automatic off
I'm not a scripter so what is the best solution
I tried with blockly but the computers don't start anymore
I think I need an delay, so when switch is off for 5 minutes --> power off computers
Who can help me
I use it for the computers of the kids
But the next step is automatic off
I'm not a scripter so what is the best solution
I tried with blockly but the computers don't start anymore
I think I need an delay, so when switch is off for 5 minutes --> power off computers
Who can help me
-
- Posts: 59
- Joined: Sunday 28 July 2019 22:59
- Target OS: NAS (Synology & others)
- Domoticz version:
- Contact:
Re: Is the washing machine done?
Hi all,
I've reinstalled domoticz on a raspberry pi (first install was on synology nas). I've imported the database from the NAS to the raspberry pi. All went well, except for a simpel script that is now giving the error:
Here's the script:
Is there anyone willing to take a look and tell me what I did wrong? It used to work on the NAS. Thanks in advance!
I've reinstalled domoticz on a raspberry pi (first install was on synology nas). I've imported the database from the NAS to the raspberry pi. All went well, except for a simpel script that is now giving the error:
Code: Select all
2020-05-14 10:21:58.229 Error: dzVents: Error: (3.0.2) An error occurred when calling event handler is de was klaar
2020-05-14 10:21:58.229 Error: dzVents: Error: (3.0.2) ...cz/scripts/dzVents/generated_scripts/is de was klaar.lua:103: attempt to compare number with nil
Code: Select all
-- create a lookup table that matches a usage
-- device to the accompanying switch
local USAGE_DEVICES = {
-- ['SC-Wasdroger verbruik'] = 'Wasdroger', -- You need to have a inline wall plug that measures energy,
['SC-Wasmachine verbruik'] = 'Wasmachine', -- here you make the link between the energy device and the wall plug.
}
local USAGE_SwitchTimeOutMinutes = {
-- ['Wasdroger'] = 6, -- Here you define how long no power is used per device.
['Wasmachine'] = 6, -- The period is in minutes. Adjust to your needs. Between every add a ",".
}
local USAGE_MaxWatt = {
-- ['Wasdroger'] = 3, -- Here you define the maximum amount of power a device uses when it is in standby.
['Wasmachine'] = 3, -- Some devices uses a little amount of power. Test it and a slightly higher usage.
}
local USAGE_Notify = {
-- ['Wasdroger'] = 'Yes', -- In some cases you want to be notified when a device is turned on and off.
['Wasmachine'] = 'Yes', -- Adjust to your needs. Between every line you need to add a ",".
}
return {
-- logging = {
-- level = domoticz.LOG_INFO, -- Uncomment to override the dzVents global logging setting
-- marker = 'POW'
-- },
on = {
timer = { 'every 5 minutes' },
devices = { -- Make sure that the devices are the same as above
-- 'SC-Wasdroger verbruik',
'SC-Wasmachine verbruik',
},
},
data = { -- use exact device names to match USAGE_DEVICES
-- ['SC-Wasdroger verbruik'] = { history = true, maxMinutes = 10 },
['SC-Wasmachine verbruik'] = { history = true, maxMinutes = 10 } --deze weer op 10 zetten straks
},
execute = function(domoticz, device)
if (device.isTimer) then
-- we need to check for expiration of grace period
domoticz.log("timer trigger")
for i, machine in pairs(USAGE_DEVICES) do
local usage = "SC-" .. machine.. " verbruik"
domoticz.log("device = " .. machine)
local actual = domoticz.devices(usage).WhActual
local average = domoticz.data[usage].avg()
domoticz.data[usage].add(actual)
domoticz.log("actual = " .. actual)
domoticz.log("average = " .. tostring(average))
local StatusWasmachine = domoticz.devices('Status wasmachine')
if actual == 0 then
domoticz.log(machine .. " gebruikt geen energie, dus is uit")
StatusWasmachine.updateText('wasmachine is uit')
domoticz.devices(machine).switchOff().checkFirst()
elseif actual < USAGE_MaxWatt[machine] then
domoticz.log(machine .. " gebruikt weinig energie, is de machine klaar?")
local timeout = USAGE_SwitchTimeOutMinutes[machine]
domoticz.log(machine .. " gebruikte gemiddeld: " .. tostring(domoticz.data[usage].avg))
if (average <= USAGE_MaxWatt[machine]) then
domoticz.log(machine .. " lijkt standby te staan, we nemen aan klaar.")
StatusWasmachine.updateText('Wasmachine is klaar')
domoticz.devices(machine).switchOff().checkFirst()
domoticz.devices('was ophangen').switchOn()
domoticz.data[usage].reset()
else
domoticz.log(machine .. " maar nog te kort om klaar te zijn.")
StatusWasmachine.updateText('Wasmachine is bijna klaar')
domoticz.devices(machine).switchOn().checkFirst()
end
else
domoticz.log(machine .. " gebruikt energie, dus is (nog) bezig.")
StatusWasmachine.updateText('Wasmachine draait')
domoticz.devices(machine).switchOn().checkFirst()
end
end
elseif (USAGE_DEVICES[device.name] ~= nil) then
-- we have a usage sensor here
domoticz.log("usage trigger")
local switch = domoticz.devices(USAGE_DEVICES[device.name])
local timeout = USAGE_SwitchTimeOutMinutes[USAGE_DEVICES[device.name]]
local watt = USAGE_MaxWatt[USAGE_DEVICES[device.name]]
domoticz.data[device.name].add(device.WhActual)
local history = domoticz.data[device.name]
domoticz.log("device = " .. device.name)
if (switch.active) then
domoticz.log("Switch is active, check average use and last update")
domoticz.log("usage last update: " .. tostring(switch.lastUpdate.minutesAgo))
domoticz.log("usage = " .. tostring(device.WhActual))
domoticz.log("average = " .. tostring(history.avg()))
if (history.avg() <= watt and device.WhActual <= watt and switch.lastUpdate.minutesAgo >= timeout) then
switch.switchOff().checkFirst()
domoticz.log("Turn switch off")
domoticz.data[device.name].reset()
end
else
domoticz.log("Switch not on")
if (device.WhActual > watt) then
domoticz.log("but power use is over treshold, turn switch on")
switch.switchOn().checkFirst()
end
end
end
end
}
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Is the washing machine done?
I don't see an obvious error so best to add some loglines.jaaap wrote: ↑Thursday 14 May 2020 10:23 Hi all,
I've reinstalled domoticz on a raspberry pi (first install was on synology nas). I've imported the database from the NAS to the raspberry pi. All went well, except for a simpel script that is now giving the error:
Code: Select all
2020-05-14 10:21:58.229 Error: dzVents: Error: (3.0.2) An error occurred when calling event handler is de was klaar 2020-05-14 10:21:58.229 Error: dzVents: Error: (3.0.2) ...cz/scripts/dzVents/generated_scripts/is de was klaar.lua:103: attempt to compare number with nil
Can you insert these lines jus above line 103?
Code: Select all
domoticz.log(device.name .. ', actual Watt = ' .. tostring(device.WhActual),domoticz.LOG_FORCE )
domoticz.log('Defined max watt ' .. tostring(watt),domoticz.LOG_FORCE )
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 59
- Joined: Sunday 28 July 2019 22:59
- Target OS: NAS (Synology & others)
- Domoticz version:
- Contact:
Re: Is the washing machine done?
So I added the lines, as you requested @waaren :
This let me to believe that SC-Wasmachine was not giving a number, but something else. I looked up SC-Wasmachine in the devices tab and found out that is was labelled as 'Custom Sensor'. In my previous install it is labelled as 'kWh'. This let me to the conclusion that SC-Wasmachine is labelled wrong in Domoticz.
I deleted the whole hs110 device in the hardware tab, re-activeted it, but still the same result.
I vaguely remember that I've adjusted a number in the domoticz database in order to change the Custom Sensor into a kWh sensor. Only I can't remember how I did it. Do you maybe know a way to do this?
UPDATE:
I found out that to change the subType you have to change the plugin itself a bit (thanks to this post: https://www.domoticz.com/forum/viewtopi ... 51#p234451 and @ajay100). Because that is where the devices are defined. In my install, on a raspberry pi, do the following:
Then go down to the part where the devices are defined and change it into (use i to insert and DEL to remove text):
The close the vi editor by typing:
Go back to domoticz, hardware tab, remove the hs110 and re-add it. Now the sensor should be of the kWh type.
Code: Select all
2020-05-14 14:08:02.629 Status: dzVents: Info: Handling events for: "SC-Wasmachine verbruik", value: "0.345"
2020-05-14 14:08:02.629 Status: dzVents: Info: ------ Start internal script: is de was klaar: Device: "SC-Wasmachine verbruik (hs110)", Index: 113
2020-05-14 14:08:02.630 Status: dzVents: Info: usage trigger
2020-05-14 14:08:02.632 Status: dzVents: Info: device = SC-Wasmachine verbruik
2020-05-14 14:08:02.632 Status: dzVents: Info: Switch not on
2020-05-14 14:08:02.632 Status: dzVents: !Info: SC-Wasmachine verbruik, actual Watt = nil
2020-05-14 14:08:02.632 Status: dzVents: !Info: Defined max watt 3
2020-05-14 14:08:02.632 Status: dzVents: Info: ------ Finished is de was klaar
2020-05-14 14:08:02.632 Error: dzVents: Error: (3.0.2) An error occurred when calling event handler is de was klaar
2020-05-14 14:08:02.632 Error: dzVents: Error: (3.0.2) ...cz/scripts/dzVents/generated_scripts/is de was klaar.lua:105: attempt to compare number with nil
I deleted the whole hs110 device in the hardware tab, re-activeted it, but still the same result.
I vaguely remember that I've adjusted a number in the domoticz database in order to change the Custom Sensor into a kWh sensor. Only I can't remember how I did it. Do you maybe know a way to do this?
UPDATE:
I found out that to change the subType you have to change the plugin itself a bit (thanks to this post: https://www.domoticz.com/forum/viewtopi ... 51#p234451 and @ajay100). Because that is where the devices are defined. In my install, on a raspberry pi, do the following:
Code: Select all
cd /home/pi/domoticz/plugins/domoticz-tplink-smartplug
vi plugin.py
Code: Select all
Domoticz.Device(Name="emeter power (W)", Unit=4, Type=243, Subtype=29).Create() # Subtype 29 is kWh
Code: Select all
:wq
Last edited by jaaap on Thursday 14 May 2020 14:30, edited 1 time in total.
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Is the washing machine done?
Before you got that path you could also try after changing
Code: Select all
device.WhActual
Code: Select all
tonumber(device.sValue)
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
- gizmocuz
- Posts: 2350
- Joined: Thursday 11 July 2013 18:59
- Target OS: Raspberry Pi / ODroid
- Domoticz version: beta
- Location: Top of the world
- Contact:
Re: Is the washing machine done?
@felix63
Thank you for the script!
I'm not sure if your latest script in the first post is still the latest code, but I found a small issue in the script.
this line:
domoticz.log(machine .. " gebruikte gemiddeld: " .. tostring(domoticz.data[usage].avg))
should be
domoticz.log(machine .. " gebruikte gemiddeld: " .. tostring(domoticz.data[usage].avg()))
"domoticz.data[usage].avg()" ... missing ()
But you already log the average value a few lines above (using the variable which is nicer), so this is a bit duplicate
Without the above fix you will see this in the log:
"maar nog te kort om klaar te zijn"
Is there a 'if/then' check missing maybe here ?
I have a few wishes:
- There seems to be two blocks of code that does the same thing (one in Dutch, the other in English), one triggered on a timer,
the other on a device usage update
Would it be nice to have one function that can be called in both cases that do all the logic ?
In that case the code is also easier to maintain
- When you have multiple devices you see a line above 'device = WasDroger', but the following log lines do not include that name, except when you say 'gebruikt geen energie, dus is uit' then you do include a device name
My suggestion is to always start with the device name (and skip the device = WasDroger log line)
- There is a little to much logging going on.... maybe get the status of the virtual switch first, and when you have a check if there is no energy used, and the switch was already off, do not log a single line
Same when value is below the threshold and the switch is already off, do not log anything for that device
Or when the switch if already on, and the avg is above the threshold do not log
Thank you for the script!
I'm not sure if your latest script in the first post is still the latest code, but I found a small issue in the script.
this line:
domoticz.log(machine .. " gebruikte gemiddeld: " .. tostring(domoticz.data[usage].avg))
should be
domoticz.log(machine .. " gebruikte gemiddeld: " .. tostring(domoticz.data[usage].avg()))
"domoticz.data[usage].avg()" ... missing ()
But you already log the average value a few lines above (using the variable which is nicer), so this is a bit duplicate
Without the above fix you will see this in the log:
In the first block you also declare the 'timeout' but you are not using it and do log2020-08-20 08:00:00.843 Status: dzVents: Info: timer trigger
2020-08-20 08:00:00.843 Status: dzVents: Info: device = Wasdroger
2020-08-20 08:00:00.857 Status: dzVents: Info: actual = 0.0
2020-08-20 08:00:00.857 Status: dzVents: Info: average = 0.0
2020-08-20 08:00:00.857 Status: dzVents: Info: Wasdroger gebruikt geen energie, dus is uit
2020-08-20 08:00:00.859 Status: dzVents: Info: device = Wasmachine
2020-08-20 08:00:00.860 Status: dzVents: Info: actual = 0.3
2020-08-20 08:00:00.860 Status: dzVents: Info: average = 0.34705882352941
2020-08-20 08:00:00.860 Status: dzVents: Info: Wasmachine gebruikt weinig energie, is de machine klaar?
2020-08-20 08:00:00.860 Status: dzVents: Info: Wasmachine gebruikte gemiddeld: function: 0xffff50064990
2020-08-20 08:00:00.860 Status: dzVents: Info: Wasmachine lijkt standby te staan, we nemen aan klaar.
"maar nog te kort om klaar te zijn"
Is there a 'if/then' check missing maybe here ?
I have a few wishes:
- There seems to be two blocks of code that does the same thing (one in Dutch, the other in English), one triggered on a timer,
the other on a device usage update
Would it be nice to have one function that can be called in both cases that do all the logic ?
In that case the code is also easier to maintain
- When you have multiple devices you see a line above 'device = WasDroger', but the following log lines do not include that name, except when you say 'gebruikt geen energie, dus is uit' then you do include a device name
My suggestion is to always start with the device name (and skip the device = WasDroger log line)
- There is a little to much logging going on.... maybe get the status of the virtual switch first, and when you have a check if there is no energy used, and the switch was already off, do not log a single line
Same when value is below the threshold and the switch is already off, do not log anything for that device
Or when the switch if already on, and the avg is above the threshold do not log
Quality outlives Quantity!
- felix63
- Posts: 244
- Joined: Monday 07 December 2015 9:30
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2020.1
- Location: Gouda
- Contact:
Re: Is the washing machine done?
Thanks for your suggestions. Will revisit the script this weekend. Will post any updates!
Verzonden vanaf mijn iPad met Tapatalk
Verzonden vanaf mijn iPad met Tapatalk
- felix63
- Posts: 244
- Joined: Monday 07 December 2015 9:30
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2020.1
- Location: Gouda
- Contact:
Re: Is the washing machine done?
@gizmocuz based on your suggestions I have revised my script. This is a new version:
Code: Select all
-- Is the washing macgine done? Version 2.0
-- create a lookup table that matches a usage
-- device to the accompanying switch
local USAGE_DEVICES = {
['SC-Wasdroger gebruik'] = 'Wasdroger', -- You need to have a inline wall plug that measures energy,
['SC-Wasmachine gebruik'] = 'Wasmachine', -- here you make the link between the energy device and the wall plug.
}
local USAGE_TimeOut = {
['Wasdroger'] = 6, -- Here you define how long no power is used per device.
['Wasmachine'] = 6, -- The period is in minutes. Adjust to your needs. Between every add a ",".
}
local USAGE_MaxWatt = {
['Wasdroger'] = 3, -- Here you define the maximum amount of power a device uses when it is in standby.
['Wasmachine'] = 3, -- Some devices uses a little amount of power. Test it and a slightly higher usage.
}
return {
logging = {
level = domoticz.LOG_INFO, -- Uncomment to override the dzVents global logging setting
marker = 'POW'
},
on = {
timer = { 'every 5 minutes' },
devices = { -- Make sure that the devices are the same as above
'SC-Wasdroger gebruik',
'SC-Wasmachine gebruik',
},
},
data = { -- use exact device names to match USAGE_DEVICES
['CountDevices'] = {initial=0},
['SC-Wasdroger gebruik'] = { history = true, maxMinutes = 10 },
['SC-Wasmachine gebruik'] = { history = true, maxMinutes = 10 },
},
execute = function(domoticz, device)
function status(machine)
local usage = "SC-" .. machine.. " gebruik" -- name of physical power measuring device
local standby = USAGE_MaxWatt[machine] -- threshold for standby
local timeout = USAGE_TimeOut[machine] -- amount of time the power consumption needs to be constant
local switch = domoticz.devices(machine) -- the actual virtual switch that shows the status of the device
local power_actual = domoticz.devices(usage).WhActual -- the actual power consumption of the device
local power_average = domoticz.data[usage].avg() -- the average power consumption in the last 10 minutes
local minutes = domoticz.devices(usage).lastUpdate.minutesAgo -- the # minutes the power consumption is unchanjged
domoticz.log("device : " .. machine .. ', power: ' .. usage)
domoticz.log('gebruik : ' .. power_actual .. ', treshold: ' .. standby)
domoticz.log('gemiddeld: ' .. power_average)
domoticz.log('sinds : ' .. minutes .. ', standby: ' .. timeout)
domoticz.data[usage].add(power_actual)
if (switch.active) then
if power_actual > standby then -- Device is already on
return('Already on')
end
if (power_actual == 0) or (power_actual <= standby and
(power_average <= standby) or minutes > standby) then
switch.switchOff() -- Device is off or on standby
domoticz.data[usage].reset() -- Reset history
return('Off')
end
return('Idle')
end
if power_actual > standby then -- Device is active
switch.switchOn() -- Turn the virtual switch on
if domoticz.data['CountDevices'] == 0 then
domoticz.data['CountDevices'] = 1 -- Keep track off active devices
end
return('Switching On')
end
if power_average > 0 then -- Switch is off but average needs to be reset
domoticz.data[usage].reset() -- Reset history
end
return('Off') -- Device is off
end
if (device.isTimer) then -- Then its a regular check
domoticz.log("Monitoring " .. tostring(domoticz.data['CountDevices']) .. " apparaten.")
if (domoticz.data['CountDevices'] > 0) then -- When one or more devices are on
domoticz.log("Monitoring " .. tostring(domoticz.data['CountDevices']) .. " apparaten.")
domoticz.data['CountDevices'] = 0 -- Reset count
for i, machine in pairs(USAGE_DEVICES) do -- Loop thru all the devices
checked = status(machine) -- Check the status of each device
domoticz.log('status: '..checked) -- Check the status of each device
if checked ~= 'Off' then
domoticz.data['CountDevices'] = domoticz.data['CountDevices'] + 1 -- Keep track off active devices
end
end
end
elseif (USAGE_DEVICES[device.name] ~= nil) then -- Then one device has a changed power consumption
domoticz.log('status: '..status(USAGE_DEVICES[device.name])) -- Check the status of this one device
end
end
}
-
- Posts: 2
- Joined: Saturday 05 December 2020 10:20
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Is the washing machine done?
Hi,
First of all, thanks for this script!
I've installed the latest script as an dzVents lua script by copy-pasting it in domoticz and every 5 minutes it runs nicely, but when I check the log it says:
2020-12-05 10:25:01.138 Status: dzVents: Info: POW: ------ Start internal script: Was_Droog:, trigger: "every 5 minutes"
2020-12-05 10:25:01.138 Status: dzVents: Info: POW: Monitoring 0 apparaten.
2020-12-05 10:25:01.139 Status: dzVents: Info: POW: ------ Finished Was_Droog
I've made the following switches: The SC-Wasmachine and SC-Wasdroger are the protected switches and physical sockets pluged in to an outlet
The SC-Wasmachine verbruik and SC-Wasdroger verbruik have the types "electrical" and are the ones having the output in Watts and I saw that they have the value of 0/xx, perhaps that's why the script is not working?
The Wasmachine and Wadroger are dummy-switches which have to be turned on and send a notification when the wasmachine or wasdroger are ready.
Can someone help me monitoring more then one apparaat (device)?
First of all, thanks for this script!
I've installed the latest script as an dzVents lua script by copy-pasting it in domoticz and every 5 minutes it runs nicely, but when I check the log it says:
2020-12-05 10:25:01.138 Status: dzVents: Info: POW: ------ Start internal script: Was_Droog:, trigger: "every 5 minutes"
2020-12-05 10:25:01.138 Status: dzVents: Info: POW: Monitoring 0 apparaten.
2020-12-05 10:25:01.139 Status: dzVents: Info: POW: ------ Finished Was_Droog
I've made the following switches: The SC-Wasmachine and SC-Wasdroger are the protected switches and physical sockets pluged in to an outlet
The SC-Wasmachine verbruik and SC-Wasdroger verbruik have the types "electrical" and are the ones having the output in Watts and I saw that they have the value of 0/xx, perhaps that's why the script is not working?
The Wasmachine and Wadroger are dummy-switches which have to be turned on and send a notification when the wasmachine or wasdroger are ready.
Can someone help me monitoring more then one apparaat (device)?
- felix63
- Posts: 244
- Joined: Monday 07 December 2015 9:30
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2020.1
- Location: Gouda
- Contact:
Re: Is the washing machine done?
Your output of the devices you use looks peculiar. Output doesn't seem to be in Watt? Can you post the info from Setup / Devices?
mine looks:
mine looks:
Code: Select all
1154 Ribes 0009301 2 SC-Wasmachine gebruik Usage Electric 0 Watt - - 2020-12-05 16:40:05
-
- Posts: 2
- Joined: Saturday 05 December 2020 10:20
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Is the washing machine done?
Hi felix63,
Thanks for replying. My screenshot is made where you can add scripts: (More options / Events)
The info from Setup / Devices is:
Today is the perfect day to test the script, because it is laundry day
Edit:
I think I see the problem. My devices are called "verbruik", in your output it says "gebruik". Oops!
It works!
2020-12-06 10:17:51.457 Status: dzVents: Info: Handling events for: "SC-Wasmachine gebruik", value: "147.0"
2020-12-06 10:17:51.458 Status: dzVents: Info: POW: ------ Start internal script: Was_Droog: Device: "SC-Wasmachine gebruik (ZWave USB)", Index: 164
2020-12-06 10:17:51.465 Status: dzVents: Info: POW: device : Wasmachine, power: SC-Wasmachine gebruik
2020-12-06 10:17:51.465 Status: dzVents: Info: POW: gebruik : 147.0, treshold: 2
2020-12-06 10:17:51.465 Status: dzVents: Info: POW: gemiddeld: 60.428571428571
2020-12-06 10:17:51.465 Status: dzVents: Info: POW: sinds : 0, standby: 6
2020-12-06 10:17:51.466 Status: dzVents: Info: POW: status: Already on
2020-12-06 10:17:51.468 Status: dzVents: Info: POW: ------ Finished Was_Droog
Thanks for replying. My screenshot is made where you can add scripts: (More options / Events)
The info from Setup / Devices is:
Code: Select all
164 ZWave USB 0011401 2 SC-Wasmachine verbruik Usage Electric 17.8 Watt - - 2020-12-06 10:05:39
Edit:
I think I see the problem. My devices are called "verbruik", in your output it says "gebruik". Oops!
It works!
2020-12-06 10:17:51.457 Status: dzVents: Info: Handling events for: "SC-Wasmachine gebruik", value: "147.0"
2020-12-06 10:17:51.458 Status: dzVents: Info: POW: ------ Start internal script: Was_Droog: Device: "SC-Wasmachine gebruik (ZWave USB)", Index: 164
2020-12-06 10:17:51.465 Status: dzVents: Info: POW: device : Wasmachine, power: SC-Wasmachine gebruik
2020-12-06 10:17:51.465 Status: dzVents: Info: POW: gebruik : 147.0, treshold: 2
2020-12-06 10:17:51.465 Status: dzVents: Info: POW: gemiddeld: 60.428571428571
2020-12-06 10:17:51.465 Status: dzVents: Info: POW: sinds : 0, standby: 6
2020-12-06 10:17:51.466 Status: dzVents: Info: POW: status: Already on
2020-12-06 10:17:51.468 Status: dzVents: Info: POW: ------ Finished Was_Droog
- felix63
- Posts: 244
- Joined: Monday 07 December 2015 9:30
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2020.1
- Location: Gouda
- Contact:
Re: Is the washing machine done?
Glad it works for you now!
Verzonden vanaf mijn iPhone met Tapatalk
Verzonden vanaf mijn iPhone met Tapatalk
-
- Posts: 15
- Joined: Sunday 16 December 2018 12:45
- Target OS: NAS (Synology & others)
- Domoticz version: 2020.1
- Contact:
Re: Is the washing machine done?
The script is running, but I don't get a message on telegram?
- felix63
- Posts: 244
- Joined: Monday 07 December 2015 9:30
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2020.1
- Location: Gouda
- Contact:
Re: Is the washing machine done?
In my case the script turns a virtual switch on and off. I added a notification to the virtual switch itself. So the notification is not done by the script itself. This gives maximal flexibility to the whole notification...
-
- Posts: 65
- Joined: Monday 25 March 2019 15:14
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Brunssum, Netherlands
- Contact:
Re: Is the washing machine done?
Good morning,
Thanks for this nice script. I am trying to test it, and the virtual switch pops on when I turn the device on. But after turning it off, the virtual switch doesn't wait 6 minutes, but pops off within seconds. Here is a part of my logfile. Does anyone know why this happens?
To test it, I plugged in a device of 66 Watt, not my washing machine.
EDIT: I think I know the problem, the script is running much more then every 5 minutes... How to fix this?
This is your script after my modification of the names of the devices:
Thanks for this nice script. I am trying to test it, and the virtual switch pops on when I turn the device on. But after turning it off, the virtual switch doesn't wait 6 minutes, but pops off within seconds. Here is a part of my logfile. Does anyone know why this happens?
To test it, I plugged in a device of 66 Watt, not my washing machine.
EDIT: I think I know the problem, the script is running much more then every 5 minutes... How to fix this?
Code: Select all
2021-01-13 09:25:18.989 Status: dzVents: Info: POW: ------ Start internal script: Wasmachine Droger status: Device: "Garage Wasmachine Verbruik (Zigbee )", Index: 2582
2021-01-13 09:25:18.992 Status: dzVents: Info: POW: device : Garage Wasmachine, power: Garage Wasmachine Verbruik
2021-01-13 09:25:18.993 Status: dzVents: Info: POW: gebruik : 66.0, treshold: 3
2021-01-13 09:25:18.993 Status: dzVents: Info: POW: gemiddeld: 33.0
2021-01-13 09:25:18.993 Status: dzVents: Info: POW: sinds : 0, standby: 6
2021-01-13 09:25:18.993 Status: dzVents: Info: POW: status: Already on
2021-01-13 09:25:18.994 Status: dzVents: Info: POW: ------ Finished Wasmachine Droger status
2021-01-13 09:25:19.176 Status: dzVents: Info: POW: ------ Start internal script: Wasmachine Droger status: Device: "Garage Wasmachine Verbruik (Zigbee )", Index: 2582
2021-01-13 09:25:19.179 Status: dzVents: Info: POW: device : Garage Wasmachine, power: Garage Wasmachine Verbruik
2021-01-13 09:25:19.180 Status: dzVents: Info: POW: gebruik : 66.0, treshold: 3
2021-01-13 09:25:19.180 Status: dzVents: Info: POW: gemiddeld: 37.714285714286
2021-01-13 09:25:19.180 Status: dzVents: Info: POW: sinds : 0, standby: 6
2021-01-13 09:25:19.180 Status: dzVents: Info: POW: status: Already on
2021-01-13 09:25:19.181 Status: dzVents: Info: POW: ------ Finished Wasmachine Droger status
2021-01-13 09:25:34.006 Status: dzVents: Info: POW: ------ Start internal script: Wasmachine Droger status: Device: "Garage Wasmachine Verbruik (Zigbee )", Index: 2582
2021-01-13 09:25:34.013 Status: dzVents: Info: POW: device : Garage Wasmachine, power: Garage Wasmachine Verbruik
2021-01-13 09:25:34.013 Status: dzVents: Info: POW: gebruik : 0.0, treshold: 3
2021-01-13 09:25:34.013 Status: dzVents: Info: POW: gemiddeld: 41.25
2021-01-13 09:25:34.013 Status: dzVents: Info: POW: sinds : 0, standby: 6
2021-01-13 09:25:34.014 Status: dzVents: Info: POW: status: Off
2021-01-13 09:25:34.015 Status: dzVents: Info: POW: ------ Finished Wasmachine Droger status
Code: Select all
-- Is the washing macgine done? Version 2.0
-- create a lookup table that matches a usage
-- device to the accompanying switch
local USAGE_DEVICES = {
['Garage Droger Verbruik'] = 'Garage Droger', -- You need to have a inline wall plug that measures energy,
['Garage Wasmachine Verbruik'] = 'Garage Wasmachine', -- here you make the link between the energy device and the wall plug.
}
local USAGE_TimeOut = {
['Garage Droger'] = 6, -- Here you define how long no power is used per device.
['Garage Wasmachine'] = 6, -- The period is in minutes. Adjust to your needs. Between every add a ",".
}
local USAGE_MaxWatt = {
['Garage Droger'] = 3, -- Here you define the maximum amount of power a device uses when it is in standby.
['Garage Wasmachine'] = 3, -- Some devices uses a little amount of power. Test it and a slightly higher usage.
}
return {
logging = {
level = domoticz.LOG_INFO, -- Uncomment to override the dzVents global logging setting
marker = 'POW'
},
on = {
timer = { 'every 5 minutes' },
devices = { -- Make sure that the devices are the same as above
'Garage Droger Verbruik',
'Garage Wasmachine Verbruik',
},
},
data = { -- use exact device names to match USAGE_DEVICES
['CountDevices'] = {initial=0},
['Garage Droger Verbruik'] = { history = true, maxMinutes = 10 },
['Garage Wasmachine Verbruik'] = { history = true, maxMinutes = 10 },
},
execute = function(domoticz, device)
function status(machine)
local usage = machine.. " Verbruik" -- name of physical power measuring device
local standby = USAGE_MaxWatt[machine] -- threshold for standby
local timeout = USAGE_TimeOut[machine] -- amount of time the power consumption needs to be constant
local switch = domoticz.devices(machine) -- the actual virtual switch that shows the status of the device
local power_actual = domoticz.devices(usage).WhActual -- the actual power consumption of the device
local power_average = domoticz.data[usage].avg() -- the average power consumption in the last 10 minutes
local minutes = domoticz.devices(usage).lastUpdate.minutesAgo -- the # minutes the power consumption is unchanjged
domoticz.log("device : " .. machine .. ', power: ' .. usage)
domoticz.log('gebruik : ' .. power_actual .. ', treshold: ' .. standby)
domoticz.log('gemiddeld: ' .. power_average)
domoticz.log('sinds : ' .. minutes .. ', standby: ' .. timeout)
domoticz.data[usage].add(power_actual)
if (switch.active) then
if power_actual > standby then -- Device is already on
return('Already on')
end
if (power_actual == 0) or (power_actual <= standby and
(power_average <= standby) or minutes > standby) then
switch.switchOff() -- Device is off or on standby
domoticz.data[usage].reset() -- Reset history
return('Off')
end
return('Idle')
end
if power_actual > standby then -- Device is active
switch.switchOn() -- Turn the virtual switch on
if domoticz.data['CountDevices'] == 0 then
domoticz.data['CountDevices'] = 1 -- Keep track off active devices
end
return('Switching On')
end
if power_average > 0 then -- Switch is off but average needs to be reset
domoticz.data[usage].reset() -- Reset history
end
return('Off') -- Device is off
end
if (device.isTimer) then -- Then its a regular check
domoticz.log("Monitoring " .. tostring(domoticz.data['CountDevices']) .. " apparaten.")
if (domoticz.data['CountDevices'] > 0) then -- When one or more devices are on
domoticz.log("Monitoring " .. tostring(domoticz.data['CountDevices']) .. " apparaten.")
domoticz.data['CountDevices'] = 0 -- Reset count
for i, machine in pairs(USAGE_DEVICES) do -- Loop thru all the devices
checked = status(machine) -- Check the status of each device
domoticz.log('status: '..checked) -- Check the status of each device
if checked ~= 'Off' then
domoticz.data['CountDevices'] = domoticz.data['CountDevices'] + 1 -- Keep track off active devices
end
end
end
elseif (USAGE_DEVICES[device.name] ~= nil) then -- Then one device has a changed power consumption
domoticz.log('status: '..status(USAGE_DEVICES[device.name])) -- Check the status of this one device
end
end
}
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
Who is online
Users browsing this forum: No registered users and 1 guest