Code: Select all
--[[
wii charger if last seen more than 5 days ago, then turn on for 1 hour.
If wii is turned off; then turn on for 2 hours.
wii heet Wii en heeft IDX: 62
wii charger heet Wii-charger en heeft IDX: 63
--]]
return {
on = {
timer = { 'at 00:58' },
-- wii heet Wii en heeft IDX: 62
devices = { 'Wii' }
},
logging = {
level = domoticz.LOG_ERROR, -- change to LOG_ERROR when script executes OK
marker = wii_charger,
},
execute = function(domoticz, item)
local charger = domoticz.devices('Wii-charger')
local wii = domoticz.devices('Wii')
-- local wii = 62
if (item.isTimer) then
-- denkfout! De Wii-charger gaat elke nacht uit ivm scheduled task
-- if (charger.lastUpdate.daysAgo > 4) then
-- dit zou moeten werken
if (wii.lastUpdate.daysAgo > 4) then
charger.switchOn()
-- force an update otherways it will trigger each following night.
wii.switchOff().silent()
end
elseif (item.isDevice and not item.active) then
-- do charge if (wii.state == 'Off')
charger.switchOn().forHour(2)
-- end
end
end
}
/var/log/domoticz/domoticz.log.11:2019-06-11 00:58:00.357 Status: dzVents: Error (2.4.22): An error occured when calling event handler wii
/var/log/domoticz/domoticz.log.11:2019-06-11 00:58:00.357 Status: dzVents: Error (2.4.22): /domoticz/scripts/dzVents/scripts/wii.lua:25: attempt to index local 'wii' (a number value)
line 25 is equal to: "if (wii.lastUpdate.daysAgo > 4) then"
However I don't see a difference with the second example underneath the link to the wiki.
Copied it here for a reference.
Code: Select all
if (domoticz.devices('My PIR').lastUpdate.minutesAgo > 5) then
domoticz.devices('Bathroom lights').switchOff()
end
Code: Select all
curl "http://127.0.0.1:8080/json.htm?type=devices&rid=62"
{
"ActTime" : 1560448733,
"AstrTwilightEnd" : "00:00",
"AstrTwilightStart" : "00:00",
"CivTwilightEnd" : "22:49",
"CivTwilightStart" : "04:31",
"DayLength" : "16:41",
"NautTwilightEnd" : "00:06",
"NautTwilightStart" : "03:14",
"ServerTime" : "2019-06-13 19:58:53",
"SunAtSouth" : "13:40",
"Sunrise" : "05:19",
"Sunset" : "22:00",
"app_version" : "4.10856",
"result" : [
{
"AddjMulti" : 1.0,
"AddjMulti2" : 1.0,
"AddjValue" : 0.0,
"AddjValue2" : 0.0,
"BatteryLevel" : 255,
"CustomImage" : 0,
"Data" : "Off",
"Description" : "",
"DimmerType" : "none",
"Favorite" : 1,
"HardwareID" : 4,
"HardwareName" : "Dummy",
"HardwareType" : "Dummy (Does nothing, use for virtual switches only)",
"HardwareTypeVal" : 15,
"HaveDimmer" : true,
"HaveGroupCmd" : true,
"HaveTimeout" : false,
"ID" : "00014129",
"Image" : "Light",
"IsSubDevice" : false,
"LastUpdate" : "2019-05-24 17:21:07",
"Level" : 0,
"LevelInt" : 0,
"MaxDimLevel" : 100,
"Name" : "Wii",
"Notifications" : "false",
"PlanID" : "0",
"PlanIDs" : [ 0 ],
"Protected" : false,
"ShowNotifications" : true,
"SignalLevel" : "-",
"Status" : "Off",
"StrParam1" : "",
"StrParam2" : "",
"SubType" : "Switch",
"SwitchType" : "On/Off",
"SwitchTypeVal" : 0,
"Timers" : "false",
"Type" : "Light/Switch",
"TypeImg" : "lightbulb",
"Unit" : 1,
"Used" : 1,
"UsedByCamera" : false,
"XOffset" : "0",
"YOffset" : "0",
"idx" : "62"
}
],
"status" : "OK",
"title" : "Devices"
}