Dear all.
I try to understand dzvents.. [ hard to get for me ]
I try to make a script wjere every month of the year is acting with Domoticz.
12 dummys that switch on the month of the year.
Looks for me a simple start to begin.Only i get unfortunately not 1 month to switch to the good month..
Is there perhaps someone that can give me some basic code from where i can start?
Thanks
Xu4: Beta Extreme antenna RFXcomE,WU Fi Ping ip P1 Gen5 PVOutput Harmony HUE SolarmanPv OTG Winddelen Alive ESP Buienradar MySensors WOL Winddelen counting RPi: Beta SMAspot RFlinkTest Domoticz ...Different backups
Derik wrote: ↑Sunday 19 August 2018 10:05
try to make a script wjere every month of the year is acting with Domoticz.
12 dummys that switch on the month of the year.
Looks for me a simple start to begin.Only i get unfortunately not 1 month to switch to the good month..
Is there perhaps someone that can give me some basic code from where i can start?
I am not sure I completely understand what you try to achieve but based on my assumption that you have created a virtual switch for every month and only want the switch with the name of the current month to be switched to On, I have put together the script below.
Please let me know if my assumption is incorrect or if you do not completely understand the script.
-- setMonthswitch.lua
return {
on = { timer = { "at 00:01" }}, -- the script will run every night at 00:01
logging = { level = domoticz.LOG_DEBUG, -- this sets the loglevel. Options are LOG_INFO, LOG_DEBUG, LOG_ERROR or LOG_FORCE
marker = "setMonthswitch" }, -- the marker will ensure you can see where information comes from
execute = function(dz) -- the parm dz (short for domoticz) will ensure all information from domoticz is available in this script
months={ "januari", -- months is here a table (or array) with all month names. The names can be accessed by months[1] .. months[12]
"februari",
"maart",
"april",
"mei",
"juni",
"juli",
"augustus",
"september",
"oktober",
"november",
"december" }
dz.log(months[tonumber(os.date("%m"))],dz.LOG_DEBUG) -- os.date("%m") returns the month-number with a leading zero as a string.
-- tonumber converts this string to a number
for i = 1,#months do -- #months means max. items in the table months (so for loop from 1 to 12)
dz.devices(months[i]).switchOff().checkFirst() -- Switch off all virtual switches labeled with names of the months
-- checkFirst() wil make sure switch will only be done when before state is different
end
dz.devices(months[tonumber(os.date("%m"))]).switchOn().checkFirst() -- Only current month switch will be set to on (when not already done)
end
}
Last edited by waaren on Monday 20 August 2018 20:36, edited 2 times in total.
bimse wrote: ↑Monday 20 August 2018 16:22
Try with
timer = { 'at 00:01 on 1/*'}, -- Every 1st of the month at 00:01
Thanks. It kind of depends what is most important for the user. With your modification the script would run once a month and thus saving CPU cycles
and it would work most of the times but if the system is down for two minutes at that particular moment the switches would show a wrong month for the whole month. With my example it would run once a day and burning CPU (0.026 seconds on my PI-3 system) and the switches could be off for a day if the system is down for two minutes on the first day of the month at 00:01)
So it is up to user environment what is most important. Execute monthly, -daily ( or even hourly ? )
2018-08-20 20:13:14.485 Status: dzVents: Error (2.4.7): error loading module 'DZ: Maanden' from file '/home/pi/domoticz/scripts/dzVents/generated_scripts/DZ: Maanden.lua':
2018-08-20 20:13:14.485 ...moticz/scripts/dzVents/generated_scripts/DZ: Maanden.lua:9: unexpected symbol near '`'
2018-08-20 20:13:14.544 Status: dzVents: Error (2.4.7): error loading module 'DZ: Maanden' from file '/home/pi/domoticz/scripts/dzVents/generated_scripts/DZ: Maanden.lua':
2018-08-20 20:13:14.544 ...moticz/scripts/dzVents/generated_scripts/DZ: Maanden.lua:9: unexpected symbol near '`'
Oops.. overlooked one quote.. I removed it in the script so please try again.
You can change the names to your liking but do not remove- or add one and they must be the same as your dummy devices.
For dzVents it does not matter what type you use in the internal event editor the type is determined in the on = section
-- setWindChill.lua
return {
on = { timer = { "every 10 minutes" }}, -- the script will run every 10 minutes
-- logging = { level = domoticz.LOG_DEBUG, -- this sets the loglevel. Options are LOG_INFO, LOG_DEBUG, LOG_ERROR or LOG_FORCE
-- marker = "setWindchill" }, -- the marker will ensure you can see where information comes from
execute = function(dz) -- the parm dz (short for domoticz) will ensure all information from domoticz is available in this script
----- enter your settings below this line -------------------------------------------------------------------------------
myTemperature = dz.devices("Buiten: Terras") -- Name of your windDevice within quotes or idx without quotes
myWind = dz.devices("D.M.: Buienradar - Wind") -- Name of your temperatureDevice within quotes or idx without quotes
myWindChill = dz.devices("D.M.: Windchill") -- Name of your windchill Device within quotes or idx without quotes
----- enter your settings above this line -------------------------------------------------------------------------------
function windChill(windSpeed, temperature)
if temperature == nil then return -99 -- Should not happen
elseif windSpeed == nil then return -99 -- Should not happen
-- chill temperature cannot be calculated for these conditions
elseif windSpeed < 1.3 or windSpeed > 49 or temperature < -46 or temperature > 17 then return temperature
end
return dz.utils.round(13.12 + (0.6215 * temperature) - (13.96 * math.pow(windSpeed, 0.16)) + (0.4867 * temperature * math.pow(windSpeed, 0.16)), 1)
end
myWindChill.updateTemperature(windChill(myWind.speed,myTemperature.temperature))
end
}
-- script_time maanden.lua
commandArray = {}
time = os.date("*t")
-- check once a minute for the months to change
if (time.month == 1) then
if otherdevices["D.M.: Januari D"] == 'Off' then
commandArray['D.M.: Januari D'] = 'On'
commandArray['D.M.: Februari D'] = 'Off'
commandArray['D.M.: Maart D'] = 'Off'
commandArray['D.M.: April D'] = 'Off'
commandArray['D.M.: Mei D'] = 'Off'
commandArray['D.M.: Juni D'] = 'Off'
commandArray['D.M.: Juli D'] = 'Off'
commandArray['D.M.: Augustus D'] = 'Off'
commandArray['D.M.: September D'] = 'Off'
commandArray['D.M.: Oktober D'] = 'Off'
commandArray['D.M.: November D'] = 'Off'
commandArray['D.M.: December D'] = 'Off'
end
elseif (time.month == 2) then
if otherdevices ["D.M.: Februari D"] == 'Off' then
commandArray['D.M.: Januari D'] = 'Off'
commandArray['D.M.: Februari D'] = 'On'
commandArray['D.M.: Maart D'] = 'Off'
commandArray['D.M.: April D'] = 'Off'
commandArray['D.M.: Mei D'] = 'Off'
commandArray['D.M.: Juni D'] = 'Off'
commandArray['D.M.: Juli D'] = 'Off'
commandArray['D.M.: Augustus D'] = 'Off'
commandArray['D.M.: September D'] = 'Off'
commandArray['D.M.: Oktober D'] = 'Off'
commandArray['D.M.: November D'] = 'Off'
commandArray['D.M.: December D'] = 'Off'
end
elseif (time.month == 3) then
if otherdevices ["D.M.: Maart D"] == 'Off' then
commandArray['D.M.: Januari D'] = 'Off'
commandArray['D.M.: Februari D'] = 'Off'
commandArray['D.M.: Maart D'] = 'On'
commandArray['D.M.: April D'] = 'Off'
commandArray['D.M.: Mei D'] = 'Off'
commandArray['D.M.: Juni D'] = 'Off'
commandArray['D.M.: Juli D'] = 'Off'
commandArray['D.M.: Augustus D'] = 'Off'
commandArray['D.M.: September D'] = 'Off'
commandArray['D.M.: Oktober D'] = 'Off'
commandArray['D.M.: November D'] = 'Off'
commandArray['D.M.: December D'] = 'Off'
end
elseif (time.month == 4) then
if otherdevices ["D.M.: April D"] == 'Off' then
commandArray['D.M.: Januari D'] = 'Off'
commandArray['D.M.: Februari D'] = 'Off'
commandArray['D.M.: Maart D'] = 'Off'
commandArray['D.M.: April D'] = 'On'
commandArray['D.M.: Mei D'] = 'Off'
commandArray['D.M.: Juni D'] = 'Off'
commandArray['D.M.: Juli D'] = 'Off'
commandArray['D.M.: Augustus D'] = 'Off'
commandArray['D.M.: September D'] = 'Off'
commandArray['D.M.: Oktober D'] = 'Off'
commandArray['D.M.: November D'] = 'Off'
commandArray['D.M.: December D'] = 'Off'
end
elseif (time.month == 5) then
if otherdevices ["D.M.: Mei D"] == 'Off' then
commandArray['D.M.: Januari D'] = 'Off'
commandArray['D.M.: Februari D'] = 'Off'
commandArray['D.M.: Maart D'] = 'Off'
commandArray['D.M.: April D'] = 'Off'
commandArray['D.M.: Mei D'] = 'On'
commandArray['D.M.: Juni D'] = 'Off'
commandArray['D.M.: Juli D'] = 'Off'
commandArray['D.M.: Augustus D'] = 'Off'
commandArray['D.M.: September D'] = 'Off'
commandArray['D.M.: Oktober D'] = 'Off'
commandArray['D.M.: November D'] = 'Off'
commandArray['D.M.: December D'] = 'Off'
end
elseif (time.month == 6) then
if otherdevices ["D.M.: Juni D"] == 'Off' then
commandArray['D.M.: Januari D'] = 'Off'
commandArray['D.M.: Februari D'] = 'Off'
commandArray['D.M.: Maart D'] = 'Off'
commandArray['D.M.: April D'] = 'Off'
commandArray['D.M.: Mei D'] = 'Off'
commandArray['D.M.: Juni D'] = 'On'
commandArray['D.M.: Juli D'] = 'Off'
commandArray['D.M.: Augustus D'] = 'Off'
commandArray['D.M.: September D'] = 'Off'
commandArray['D.M.: Oktober D'] = 'Off'
commandArray['D.M.: November D'] = 'Off'
commandArray['D.M.: December D'] = 'Off'
end
elseif (time.month == 7) then
if otherdevices ["D.M.: Juli D"] == 'Off' then
commandArray['D.M.: Januari D'] = 'Off'
commandArray['D.M.: Februari D'] = 'Off'
commandArray['D.M.: Maart D'] = 'Off'
commandArray['D.M.: April D'] = 'Off'
commandArray['D.M.: Mei D'] = 'Off'
commandArray['D.M.: Juni D'] = 'Off'
commandArray['D.M.: Juli D'] = 'On'
commandArray['D.M.: Augustus D'] = 'Off'
commandArray['D.M.: September D'] = 'Off'
commandArray['D.M.: Oktober D'] = 'Off'
commandArray['D.M.: November D'] = 'Off'
commandArray['D.M.: December D'] = 'Off'
end
elseif (time.month == 8) then
if otherdevices ["D.M.: Augustus D"] == 'Off' then
commandArray['D.M.: Januari D'] = 'Off'
commandArray['D.M.: Februari D'] = 'Off'
commandArray['D.M.: Maart D'] = 'Off'
commandArray['D.M.: April D'] = 'Off'
commandArray['D.M.: Mei D'] = 'Off'
commandArray['D.M.: Juni D'] = 'Off'
commandArray['D.M.: Juli D'] = 'Off'
commandArray['D.M.: Augustus D'] = 'On'
commandArray['D.M.: September D'] = 'Off'
commandArray['D.M.: Oktober D'] = 'Off'
commandArray['D.M.: November D'] = 'Off'
commandArray['D.M.: December D'] = 'Off'
end
elseif (time.month == 9) then
if otherdevices ["D.M.: September D"] == 'Off' then
commandArray['D.M.: Januari D'] = 'Off'
commandArray['D.M.: Februari D'] = 'Off'
commandArray['D.M.: Maart D'] = 'Off'
commandArray['D.M.: April D'] = 'Off'
commandArray['D.M.: Mei D'] = 'Off'
commandArray['D.M.: Juni D'] = 'Off'
commandArray['D.M.: Juli D'] = 'Off'
commandArray['D.M.: Augustus D'] = 'Off'
commandArray['D.M.: September D'] = 'On'
commandArray['D.M.: Oktober D'] = 'Off'
commandArray['D.M.: November D'] = 'Off'
commandArray['D.M.: December D'] = 'Off'
end
elseif (time.month == 10) then
if otherdevices ["D.M.: Oktober D"] == 'Off' then
commandArray['D.M.: Januari D'] = 'Off'
commandArray['D.M.: Februari D'] = 'Off'
commandArray['D.M.: Maart D'] = 'Off'
commandArray['D.M.: April D'] = 'Off'
commandArray['D.M.: Mei D'] = 'Off'
commandArray['D.M.: Juni D'] = 'Off'
commandArray['D.M.: Juli D'] = 'Off'
commandArray['D.M.: Augustus D'] = 'Off'
commandArray['D.M.: September D'] = 'Off'
commandArray['D.M.: Oktober D'] = 'On'
commandArray['D.M.: November D'] = 'Off'
commandArray['D.M.: December D'] = 'Off'
end
elseif (time.month == 11) then
if otherdevices ["D.M.: November D"] == 'Off' then
commandArray['D.M.: Januari D'] = 'Off'
commandArray['D.M.: Februari D'] = 'Off'
commandArray['D.M.: Maart D'] = 'Off'
commandArray['D.M.: April D'] = 'Off'
commandArray['D.M.: Mei D'] = 'Off'
commandArray['D.M.: Juni D'] = 'Off'
commandArray['D.M.: Juli D'] = 'Off'
commandArray['D.M.: Augustus D'] = 'Off'
commandArray['D.M.: September D'] = 'Off'
commandArray['D.M.: Oktober D'] = 'Off'
commandArray['D.M.: November D'] = 'On'
commandArray['D.M.: December D'] = 'Off'
end
elseif (time.month == 12) then
if otherdevices ["D.M.: December D"] == 'Off' then
commandArray['D.M.: Januari D'] = 'Off'
commandArray['D.M.: Februari D'] = 'Off'
commandArray['D.M.: Maart D'] = 'Off'
commandArray['D.M.: April D'] = 'Off'
commandArray['D.M.: Mei D'] = 'Off'
commandArray['D.M.: Juni D'] = 'Off'
commandArray['D.M.: Juli D'] = 'Off'
commandArray['D.M.: Augustus D'] = 'Off'
commandArray['D.M.: September D'] = 'Off'
commandArray['D.M.: Oktober D'] = 'Off'
commandArray['D.M.: November D'] = 'Off'
commandArray['D.M.: December D'] = 'On'
end
else
print('Er is iets mis in het script van Maanden :)')
end
return commandArray
Xu4: Beta Extreme antenna RFXcomE,WU Fi Ping ip P1 Gen5 PVOutput Harmony HUE SolarmanPv OTG Winddelen Alive ESP Buienradar MySensors WOL Winddelen counting RPi: Beta SMAspot RFlinkTest Domoticz ...Different backups