Page 1 of 1
Problem with script sunscreen
Posted: Thursday 23 May 2019 19:29
by EdwinK
Since sometime I've been using this script, created by user Rembo
- Spoiler: show
Code: Select all
-- Define all the sensors which needs to be considered for the sunscreen to close
local sensors = {
temperature = {
active = true,
device = 'Temperature', --'Buienradar - Temperature',
closeRule = function(device)
return device.temperature <= 19
end
},
wind = {
active = true,
device = 'Buienradar - Wind',
closeRule = function(device)
return device.speed >= 50 or device.gust >= 150
end
},
rain = {
active = true,
device = 'Rain',
closeRule = function(device)
return device.rainRate > 0
end
},
rainExpected = {
active = false,
device = 'IsItGonnaRain', -- This needs to be a virtual sensor of type 'percentage'
closeRule = function(device)
return device.percentage > 15
end
},
uv = {
active = false,
device = 'Wu - Uv',
closeRule = function(device)
return device.uv <= 2
end
},
lux = {
active = true,
device = 'LUX',
closeRule = function(device)
return device.lux <= 500
end
}
}
local sunscreenDevice = 'Sunscreen' -- Define the name of your sunscreen device
local dryRun = 'Y' -- Enable dry run mode to test the sunscreen script without actually activating the sunscreen
-- Define the name of a virtual switch which you can use to disable the sunscreen automation script, Set to false to disable this feature
local manualOverrideSwitch = 'Sunscreen - Manual'
local timeBetweenOpens = 10 -- Minutes to wait after a sunscreen close before opening it again.
local LogFile= '/home/pi/domoticz/Logs/Sunscreen.csv ~m.csv'
local LogAction = 'N'
local message = '.'
return {
active = true,
on = { timer = {'every minute'} },
logging = { level = domoticz.LOG_DEBUG,
marker = 'Sunscreen' },
data = { safedMessage = { initial = "-" } },
execute = function(domoticz)
-- FUNCTIONS
function LogActions()
-- LogFile=string.gsub(LogFile,"~d",os.date("%Y-%m-%d"))
LogFile=string.gsub(LogFile,"~m",os.date("%Y-%m"))
if not My.File_exists(LogFile) then
f=io.open(LogFile,"a")
f:write("Datum ; Tijd ; dryRun ; Manual_or_Auto ; Message")
f:write("\r\n")
else
f=io.open(LogFile,"r")
c=f:read("*line")
f:close()
f=io.open(LogFile,"a")
end
if domoticz.data.safedMessage == message then
domoticz.log("Same message skip write action",domoticz.LOG_DEBUG)
else
domoticz.data.safedMessage = message
f:write(os.date("%Y-%m-%d;%H:%M:%S") .. ";" .. dryRun .. ";" .. domoticz.devices(manualOverrideSwitch).state .. ";" .. message )
f:write("\r\n")
end
f:close()
end
local function switchOn(sunscreen, message)
if LogAction == 'Y' or LogAction == 'A' then LogActions() end
if (sunscreen.state == 'Closed') then
if dryRun == 'N' then
sunscreen.switchOn()
--domoticz.notify('Sunscreen', message)
end
domoticz.log(message, domoticz.LOG_INFO)
--domoticz.notify('Sunscreen', message)
else
domoticz.log('Sunscreen is already down' , domoticz.LOG_INFO)
end
if LogAction == 'Y' or LogAction == 'A' then LogActions() end
end
local function switchOff(sunscreen, message)
if (sunscreen.state == 'Open') then
if dryRun == 'N' then
sunscreen.switchOff()
end
domoticz.log(message, domoticz.LOG_INFO)
--domoticz.notify('Sunscreen', message)
end
if LogAction == 'Y' or LogAction == 'A' then LogActions() end
end
-- PROGRAM STARTS
if (manualOverrideSwitch and domoticz.devices(manualOverrideSwitch).state == 'On') then
domoticz.log('Automatic sunscreen script is manually disabled', domoticz.LOG_DEBUG)
return
end
local sunscreen = domoticz.devices(sunscreenDevice)
-- Sunscreen must always be up during nighttime
if (domoticz.time.isNightTime) then
message = 'Raising sunscreen, It is night'
switchOff(sunscreen, message)
if LogAction == 'Y' or LogAction == 'A' then LogActions() end
return
end
-- Check all sensor tresholds and if any exeeded close sunscreen
for sensorType, sensor in pairs(sensors) do
if (sensor['active'] == true) then
local device = domoticz.devices(sensor['device'])
local closeRule = sensor['closeRule']
domoticz.log('Checking sensor: ' .. sensorType, domoticz.LOG_DEBUG)
if (closeRule(device)) then
message = (sensorType .. ' treshold exceeded , Sunscreen up')
switchOff(sunscreen, message )
domoticz.log(message, domoticz.LOG_DEBUG)
if LogAction == 'Y' or LogAction == 'A' then LogActions() end
-- Return early when we exeed any tresholds
return
end
else
domoticz.log('Sensor not active skipping: ' .. sensorType, domoticz.LOG_DEBUG)
end
end
-- All tresholds OK, sunscreen may be lowered
if (sunscreen.lastUpdate.minutesAgo > timeBetweenOpens) then
message = 'Sun is shining, all thresholds OK, lowering sunscreen'
switchOn(sunscreen, message)
end
end
}
It sued to be working. But now that the weather is getting in the higher regions I noticed that it didn't actually let the sunscreen raise/lower. I can however send the command directly from the dashboard and then it's working. But not automatically. But.. the log reads:
2019-05-23 19:27:00.314 Status: dzVents: Info: Sunscreen: ------ Start internal script: SunScreen:, trigger: every minute
2019-05-23 19:27:00.316 Status: dzVents: Debug: Sunscreen: Processing device-adapter for Sunscreen - Manual: Switch device adapter
2019-05-23 19:27:00.317 Status: dzVents: Debug: Sunscreen: Processing device-adapter for Sunscreen: Switch device adapter
2019-05-23 19:27:00.317 Status: dzVents: Debug: Sunscreen: Checking sensor: lux
2019-05-23 19:27:00.317 Status: dzVents: Debug: Sunscreen: Sensor not active skipping: uv
2019-05-23 19:27:00.318 Status: dzVents: Debug: Sunscreen: Processing device-adapter for Buienradar - Wind: Wind device adapter
2019-05-23 19:27:00.318 Status: dzVents: Debug: Sunscreen: Checking sensor: wind
2019-05-23 19:27:00.319 Status: dzVents: Debug: Sunscreen: Processing device-adapter for Temperature: Temperature device adapter
2019-05-23 19:27:00.319 Status: dzVents: Debug: Sunscreen: Checking sensor: temperature
2019-05-23 19:27:00.319 Status: dzVents: Debug: Sunscreen: Sensor not active skipping: rainExpected
2019-05-23 19:27:00.320 Status: dzVents: Debug: Sunscreen: Processing device-adapter for Rain: Rain device
2019-05-23 19:27:00.320 Status: dzVents: Debug: Sunscreen: Checking sensor: rain
2019-05-23 19:27:00.320 Status: dzVents: Info: Sunscreen: Sun is shining, all thresholds OK, lowering sunscreen
2019-05-23 19:27:00.320 Status: dzVents: Info: Sunscreen: ------ Finished SunScreen
So you would think it is working.
Re: Problem with script sunscreen
Posted: Friday 24 May 2019 0:52
by waaren
EdwinK wrote: ↑Thursday 23 May 2019 19:29
Since sometime I've been using this script, created by user Rembo
It used to be working. But now that the weather is getting in the higher regions I noticed that it didn't actually let the sunscreen raise/lower. I can however send the command directly from the dashboard and then it's working. But not automatically. But.. the log reads:
local dryRun = 'Y' ?? -- Enable dry run mode to test the sunscreen script without actually activating the sunscreen
Re: Problem with script sunscreen
Posted: Friday 24 May 2019 12:29
by EdwinK
Damn.. Overlooked that one. Had it turned on to test somethings. Changed it back and screen was lowering it self right away.
Now trying to find a good rain percentage script and an UV one.
Re: Problem with script sunscreen
Posted: Sunday 06 June 2021 12:39
by EdwinK
And now again it doesn't work well.
The script is executing, and tells met that the screen is down, but in fact it isn't. This time I checked if the dryrun is turned off,
local dryRun = 'N' -- Enable dry run mode to test the sunscreen script without actually activating the sunscreen
and also the switch in local manualOverrideSwitch = 'Sunscreen - Manual' is set to automatic.
the screen itself will be lowered when I click the button on the tablet. So,, also the KaKu device is working.
The script:
Code: Select all
-- Define all the sensors which needs to be considered for the sunscreen to raise
local sensors = {
temperature = {
active = true,
device = 'TempHumBaro',
closeRule = function(device)
return device.temperature <= 19
end
},
wind = {
active = true,
device = 'Wind',
closeRule = function(device)
return device.speed >= 50 or device.gust >= 150
end
},
rain = {
active = true,
device = 'Rain',
closeRule = function(device)
return device.rainRate > 0
end
},
rainExpected = {
active = false,
device = 'BR Regen Percentage', -- This needs to be a virtual sensor of type 'percentage'
closeRule = function(device)
return device.percentage > 15
end
},
uv = {
active = true,
device = 'UV Index',
closeRule = function(device)
return device.uv <= 2
end
},
lux = {
active = true,
device = 'LUX',
closeRule = function(device)
return device.lux <= 500
end
}
}
local sunscreenDevice = 'Sunscreen' -- Define the name of your sunscreen device
local dryRun = 'N' -- Enable dry run mode to test the sunscreen script without actually activating the sunscreen
-- Define the name of a virtual switch which you can use to disable the sunscreen automation script, Set to false to disable this feature
local manualOverrideSwitch = 'Sunscreen - Manual'
local timeBetweenOpens = 10 -- Minutes to wait after a sunscreen close before opening it again.
local LogFile = '/home/pi/domoticz/Logs/Sunscreen.csv ~m.csv'
local LogAction = 'N'
local message = '.'
return {
active = true,
on = { timer = {'every minute'} },
logging = { level = domoticz.LOG_DEBUG,
marker = 'Sunscreen' },
data = { safedMessage = { initial = "-" } },
execute = function(domoticz)
-- FUNCTIONS
function LogActions()
-- LogFile=string.gsub(LogFile,"~d",os.date("%Y-%m-%d"))
LogFile=string.gsub(LogFile,"~m",os.date("%Y-%m"))
if not My.File_exists(LogFile) then
f=io.open(LogFile,"a")
f:write("Datum ; Tijd ; dryRun ; Manual_or_Auto ; Message")
f:write("\r\n")
else
f=io.open(LogFile,"r")
c=f:read("*line")
f:close()
f=io.open(LogFile,"a")
end
if domoticz.data.safedMessage == message then
domoticz.log("Same message skip write action",domoticz.LOG_DEBUG)
else
domoticz.data.safedMessage = message
f:write(os.date("%Y-%m-%d;%H:%M:%S") .. ";" .. dryRun .. ";" .. domoticz.devices(manualOverrideSwitch).state .. ";" .. message )
f:write("\r\n")
end
f:close()
end
local function switchOn(sunscreen, message)
if LogAction == 'Y' or LogAction == 'A' then LogActions() end
if (sunscreen.state == 'Closed') then
if dryRun == 'N' then
sunscreen.switchOn()
--domoticz.notify('Sunscreen', message)
end
domoticz.log(message, domoticz.LOG_INFO)
--domoticz.notify('Sunscreen', message)
else
domoticz.log('Zonnescherm is al uit' , domoticz.LOG_INFO)
end
if LogAction == 'Y' or LogAction == 'A' then LogActions() end
end
local function switchOff(sunscreen, message)
if (sunscreen.state == 'Open') then
if dryRun == 'N' then
sunscreen.switchOff()
end
domoticz.log(message, domoticz.LOG_INFO)
--domoticz.notify('Sunscreen', message)
end
if LogAction == 'Y' or LogAction == 'A' then LogActions() end
end
-- PROGRAM STARTS
if (manualOverrideSwitch and domoticz.devices(manualOverrideSwitch).state == 'On') then
domoticz.log('Script is handmatig uitgezet', domoticz.LOG_DEBUG)
return
end
local sunscreen = domoticz.devices(sunscreenDevice)
-- Sunscreen must always be up during nighttime
if (domoticz.time.isNightTime) then
message = 'Zonneschermm omhoog, het is nacht'
switchOff(sunscreen, message)
if LogAction == 'Y' or LogAction == 'A' then LogActions() end
return
end
-- Check all sensor tresholds and if any exeeded close sunscreen
for sensorType, sensor in pairs(sensors) do
if (sensor['active'] == true) then
local device = domoticz.devices(sensor['device'])
local closeRule = sensor['closeRule']
domoticz.log('Checking sensor: ' .. sensorType, domoticz.LOG_DEBUG)
if (closeRule(device)) then
message = (sensorType .. ' drempel overschreden , scherm omhoog')
switchOff(sunscreen, message )
domoticz.log(message, domoticz.LOG_DEBUG)
if LogAction == 'Y' or LogAction == 'A' then LogActions() end
-- Return early when we exeed any tresholds
return
end
else
domoticz.log('Sensor niet actief: ' .. sensorType, domoticz.LOG_DEBUG)
end
end
-- All tresholds OK, sunscreen may be lowered
if (sunscreen.lastUpdate.minutesAgo > timeBetweenOpens) then
message = 'Zon schijnt, drempels ok, scherm omlaag'
switchOn(sunscreen, message)
end
end
}
Re: Problem with script sunscreen
Posted: Wednesday 25 August 2021 21:56
by ricvee
About the switch in local manualOverrideSwitch = 'Sunscreen - Manual':
I made a Dummy switch Sunscreen - Manual, but how to make this work?
Do you connect this Dummy to the device Sunscreen as a Slave or something?
I do not understand how I can switch this switch automatic when I manually switch the Sunscreen,
Can you help me out?
Re: Problem with script sunscreen
Posted: Wednesday 25 August 2021 22:32
by EdwinK
Make that switch, and in the script in the line with"
local manualOverrideSwitch = '[[Your Switch]]'
you the name of your switch.
Re: Problem with script sunscreen
Posted: Thursday 26 August 2021 7:45
by ricvee
I did make that virtual switch, but I don't understand how this switch is being triggered.
Re: Problem with script sunscreen
Posted: Thursday 26 August 2021 9:40
by waltervl
ricvee wrote: ↑Thursday 26 August 2021 7:45
I did make that virtual switch, but I don't understand how this switch is being triggered.
If you switch that virtual override switch manually to ON the script will stop controlling the sunscreens. If you switch it to OFF it will continue controlling the sunscreens.
Code: Select all
if (manualOverrideSwitch and domoticz.devices(manualOverrideSwitch).state == 'On') then
domoticz.log('Script is handmatig uitgezet', domoticz.LOG_DEBUG)
return
end
Re: Problem with script sunscreen
Posted: Thursday 26 August 2021 13:11
by ricvee
Ok, thanks!
Re: Problem with script sunscreen
Posted: Friday 17 September 2021 15:36
by EdwinK
Again i have the problem that my sunscreen isn't working anymore.
This is my script (user @Rembo created it some time ago)
- Spoiler: show
-
-- Define all the sensors which needs to be considered for the sunscreen to raise
local sensors = {
temperature = {
active = true,
device = 'TempHumBaro',
closeRule = function(device)
return device.temperature <= 19
end
},
wind = {
active = true,
device = 'Wind',
closeRule = function(device)
return device.speed >= 50 or device.gust >= 150
end
},
rain = {
active = true,
device = 'Rain',
closeRule = function(device)
return device.rainRate > 0
end
},
rainExpected = {
active = true,
device = 'BR Regen Percentage', -- This needs to be a virtual sensor of type 'percentage'
closeRule = function(device)
return device.percentage > 15
end
},
uv = {
active = true,
device = 'UV Index',
closeRule = function(device)
return device.uv <= 2
end
},
lux = {
active = true,
device = 'LUX',
closeRule = function(device)
return device.lux <= 500
end
}
}
local sunscreenDevice = 'Sunscreen' -- Define the name of your sunscreen device
local dryRun = 'N' -- Enable dry run mode to test the sunscreen script without actually activating the sunscreen
-- Define the name of a virtual switch which you can use to disable the sunscreen automation script, Set to false to disable this feature
-- local manualOverrideSwitch = 'Sunscreen - Manual'
local timeBetweenOpens = 10 -- Minutes to wait after a sunscreen close before opening it again.
local LogFile = '/home/pi/domoticz/Logs/Sunscreen.csv ~m.csv'
local LogAction = 'N'
local message = '.'
return {
active = true,
on = { timer = {'every minute'} },
logging = { level = domoticz.LOG_INFO,
marker = 'Sunscreen' },
data = { safedMessage = { initial = "-" } },
execute = function(domoticz)
-- FUNCTIONS
function LogActions()
-- LogFile=string.gsub(LogFile,"~d",os.date("%Y-%m-%d"))
LogFile=string.gsub(LogFile,"~m",os.date("%Y-%m"))
if not My.File_exists(LogFile) then
f=io.open(LogFile,"a")
f:write("Datum ; Tijd ; dryRun ; Manual_or_Auto ; Message")
f:write("\r\n")
else
f=io.open(LogFile,"r")
c=f:read("*line")
f:close()
f=io.open(LogFile,"a")
end
if domoticz.data.safedMessage == message then
domoticz.log("Same message skip write action",domoticz.LOG_DEBUG)
else
domoticz.data.safedMessage = message
f:write(os.date("%Y-%m-%d;%H:%M:%S") .. ";" .. dryRun .. ";" .. domoticz.devices(manualOverrideSwitch).state .. ";" .. message )
f:write("\r\n")
end
f:close()
end
local function switchOn(sunscreen, message)
if LogAction == 'Y' or LogAction == 'A' then LogActions() end
if (sunscreen.state == 'Closed') then
if dryRun == 'N' then
sunscreen.switchOn()
--domoticz.notify('Sunscreen', message)
end
domoticz.log(message, domoticz.LOG_INFO)
--domoticz.notify('Sunscreen', message)
else
domoticz.log('Zonnescherm is al neer' , domoticz.LOG_INFO)
end
if LogAction == 'Y' or LogAction == 'A' then LogActions() end
end
local function switchOff(sunscreen, message)
if (sunscreen.state == 'Open') then
if dryRun == 'N' then
sunscreen.switchOff()
end
domoticz.log(message, domoticz.LOG_INFO)
--domoticz.notify('Sunscreen', message)
end
if LogAction == 'Y' or LogAction == 'A' then LogActions() end
end
-- PROGRAM STARTS
if (manualOverrideSwitch and domoticz.devices(manualOverrideSwitch).state == 'On') then
domoticz.log('Script is handmatig uitgezet', domoticz.LOG_DEBUG)
return
end
local sunscreen = domoticz.devices(sunscreenDevice)
-- Sunscreen must always be up during nighttime
if (domoticz.time.isNightTime) then
message = 'Zonneschermm omhoog, het is nacht'
switchOff(sunscreen, message)
if LogAction == 'Y' or LogAction == 'A' then LogActions() end
return
end
-- Check all sensor tresholds and if any exeeded close sunscreen
for sensorType, sensor in pairs(sensors) do
if (sensor['active'] == true) then
local device = domoticz.devices(sensor['device'])
local closeRule = sensor['closeRule']
domoticz.log('Checking sensor: ' .. sensorType, domoticz.LOG_DEBUG)
if (closeRule(device)) then
message = (sensorType .. ' treshold exceeded , Sunscreen up')
switchOff(sunscreen, message )
domoticz.log(message, domoticz.LOG_DEBUG)
if LogAction == 'Y' or LogAction == 'A' then LogActions() end
-- Return early when we exeed any tresholds
return
end
else
domoticz.log('Sensor not active skipping: ' .. sensorType, domoticz.LOG_DEBUG)
end
end
-- All tresholds OK, sunscreen may be lowered
if (sunscreen.lastUpdate.minutesAgo > timeBetweenOpens) then
message = 'Sun is shining, all thresholds OK, lowering sunscreen'
switchOn(sunscreen, message)
end
end
}
Instead of a KaKu/CoCo switch I now use a Shelly 2.5 in roller/shutter mode. I made sure it had to correct name, but somehow I'm missing something.
Re: Problem with script sunscreen
Posted: Friday 17 September 2021 15:47
by waltervl
@EdwinK Hard to see what is wrong without knowing what you changed exactly.....
And is there an error shown? What is not working anymore?
Re: Problem with script sunscreen
Posted: Friday 17 September 2021 16:34
by EdwinK
The problem is that there are no errors shown. According to the log the screen is down, when it's not. I changed from KaKu to Shelly 2.5, changed the name of the device so that it is the same as with is in the script.
Status:
2021-09-17 16:25:00.683 Status: dzVents: Info: Sunscreen: ------ Start internal script: SunScreen:, trigger: "every minute"
2021-09-17 16:25:00.689 Status: dzVents: Info: Sunscreen: Zonnescherm is al neer
2021-09-17 16:25:00.689 Status: dzVents: Info: Sunscreen: ------ Finished SunScreen
2021-09-17 16:26:00.152 Status: dzVents: Info: Sunscreen: ------ Start internal script: SunScreen:, trigger: "every minute"
2021-09-17 16:26:00.159 Status: dzVents: Info: Sunscreen: Zonnescherm is al neer
So the script its self is working somehow it's just not lowering the screen.
Re: Problem with script sunscreen
Posted: Friday 17 September 2021 18:01
by waltervl
Did you check the state of the blinds switch in events? Open/Close, On/Off?
Do you use the same states to check?
Blinds Open/Close, On/Off could be the other way around.
Else log the states in extra debug logging to see what is going on.