Need help with sunscreen script  [Solved]

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

Moderator: leecollings

Post Reply
drwurn
Posts: 68
Joined: Sunday 10 June 2018 16:59
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Need help with sunscreen script

Post by drwurn »

Since I can't make such a script with blockly cause of the multiple 'if' I need some help with dzvents. Did some reading on wiki and the forum but guess I'm not much of a script writer.

The weather conditions are from darksky

What I want to create is the following:

If
'zonnescherm' is closed
Time is between 11.30 and sunset
Date is between 1 april and 30 september
'Windsnelheid Assen' <8
'UV Index Assen' >1
'Regen voorspelling Assen' <1

Then
Set 'Zonnescherm' On

If 'Zonnescherm' is On and one of the conditions changing, 'Zonnescherm' should close. (Off)


Not sure if I'm missing something.

Who can help me with creating this?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Need help with sunscreen script

Post by waaren »

drwurn wrote: Tuesday 09 October 2018 12:42 Since I can't make such a script with blockly cause of the multiple 'if' I need some help with dzvents. Did some reading on wiki and the forum but guess I'm not much of a script writer.
Spoiler: show

Code: Select all

If
'zonnescherm' is closed
Time is between 11.30 and sunset
Date is between 1 april and 30 september
'Windsnelheid Assen' <8
'UV Index Assen' >1
'Regen voorspelling Assen' <1

Then
Set 'Zonnescherm' On

If 'Zonnescherm' is On and one of the conditions changing, 'Zonnescherm' should close. (Off)

Who can help me with creating this?
Could be something like this

Code: Select all

-- sunProtection.lua
return { 
        on =        { timer   =   {"every 10 minutes between 11:30 and 10 minute after sunset on 1/4-30/9"}},
    
        logging =   {   level   =   domoticz.LOG_DEBUG,
                        marker  =   "Sunscreen" },
    
    execute = function(dz)
        local sunscreen       = dz.devices(###)                      -- replace ### by your sunscreen device IDX 
        local windSpeed       = dz.devices(###).speed                 -- replace ### by your virtual wind device IDX 
        local UV              = dz.devices(###).uv                    -- replace ### by your virtual UV device IDX   
        local rainPrediction  = tonumber(dz.devices(###).state)       -- replace ### by your virtual rainprediction device IDX     
        
        local OnConditionsMet =  sunscreen.state == "Open" and   -- Maybe you need to reverse this to ~= or to "Closed"
                                 windSpeed < 8 and
                                 UV > 1 and
                                 rainPrediction < 1 and
                                 dz.time.matchesRule("between 11:30 and sunset") 
        
        if OnConditionsMet then
            sunscreen.switchOff()
        else
            sunscreen.switchOn().checkFirst()
        end   
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
drwurn
Posts: 68
Joined: Sunday 10 June 2018 16:59
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Need help with sunscreen script

Post by drwurn »

waaren wrote: Tuesday 09 October 2018 21:10
drwurn wrote: Tuesday 09 October 2018 12:42 Since I can't make such a script with blockly cause of the multiple 'if' I need some help with dzvents. Did some reading on wiki and the forum but guess I'm not much of a script writer.
Spoiler: show

Code: Select all

If
'zonnescherm' is closed
Time is between 11.30 and sunset
Date is between 1 april and 30 september
'Windsnelheid Assen' <8
'UV Index Assen' >1
'Regen voorspelling Assen' <1

Then
Set 'Zonnescherm' On

If 'Zonnescherm' is On and one of the conditions changing, 'Zonnescherm' should close. (Off)

Who can help me with creating this?
Could be something like this

Code: Select all

-- sunProtection.lua
return { 
        on =        { timer   =   {"every 10 minutes between 11:30 and 10 minute after sunset on 1/4-30/9"}},
    
        logging =   {   level   =   domoticz.LOG_DEBUG,
                        marker  =   "Sunscreen" },
    
    execute = function(dz)
        local sunscreen       = dz.devices(###)                      -- replace ### by your sunscreen device IDX 
        local windSpeed       = dz.devices(###).speed                 -- replace ### by your virtual wind device IDX 
        local UV              = dz.devices(###).uv                    -- replace ### by your virtual UV device IDX   
        local rainPrediction  = tonumber(dz.devices(###).state)       -- replace ### by your virtual rainprediction device IDX     
        
        local OnConditionsMet =  sunscreen.state == "Open" and   -- Maybe you need to reverse this to ~= or to "Closed"
                                 windSpeed < 8 and
                                 UV > 1 and
                                 rainPrediction < 1 and
                                 dz.time.matchesRule("between 11:30 and sunset") 
        
        if OnConditionsMet then
            sunscreen.switchOff()
        else
            sunscreen.switchOn().checkFirst()
        end   
    end
}
That looks good.
I've spend the intire evening on this script.

Code: Select all

return {
   on = {
       timer = { 'on 1/4-30/9 between 11:30 and sunset' },
         },
   execute = function (domoticz, item)
      if item.isTimer and
      domoticz.devices('Test lamp').state == "On" and 
      domoticz.devices('UV Index Assen').uv >0 then
         domoticz.devices('Dummy Zonnescherm').switchOn()
      else
         domoticz.devices('Dummy Zonnescherm').switchOff()
      end
   end
}
 
Still not finished and needs testing.
Also need to work out how to get a message when the sunscreen is set to off, and which variable causes it.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Need help with sunscreen script

Post by waaren »

drwurn wrote: Tuesday 09 October 2018 23:48 Also need to work out how to get a message when the sunscreen is set to off, and which variable causes it.
Does this help ?

Code: Select all

-- sunProtection.lua
return { 
        on =        { timer   =   {"every 10 minutes between 11:30 and 10 minute after sunset on 1/4-30/9"}},
    
        logging =   {   level   =   domoticz.LOG_DEBUG,
                        marker  =   "Sunscreen" },
    
    execute = function(dz)
        local sunscreen       = dz.devices(###)                      -- replace ### by your sunscreen device IDX 
        local windSpeed       = dz.devices(###).speed                 -- replace ### by your virtual wind device IDX 
        local UV              = dz.devices(###).uv                    -- replace ### by your virtual UV device IDX   
        local rainPrediction  = tonumber(dz.devices(###).state)       -- replace ### by your virtual rainprediction device IDX     
        
        local OnConditionsMet =  sunscreen.state == "Open" and   -- Maybe you need to reverse this to ~= or to "Closed"
                                 windSpeed < 8 and
                                 UV > 1 and
                                 rainPrediction < 1 and
                                 dz.time.matchesRule("between 11:30 and sunset") 
        
        if OnConditionsMet then
            sunscreen.switchOff()
        else
            if sunscreen.state == "Closed " then 
                sunscreen.switchOn()
                if windSpeed    >= 8 then dz.notify(sunscreen.name .. " closed because of windspeed " .. windSpeed)
                elseif UV           <= 1 then dz.notify(sunscreen.name .. " closed because of UV " .. UV)
                elseif rainPrediction    >= 1 then dz.notify(sunscreen.name .. " closed because of rainPrediction " .. rainPrediction)
                else dz.notify(sunscreen.name .. " closed because of timerule " )
                end
            end 
        end   
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
drwurn
Posts: 68
Joined: Sunday 10 June 2018 16:59
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Need help with sunscreen script

Post by drwurn »

I've made a dummy switch for the sunscreen for testing.
The dummy switch turned on this morning but didn't turn off after sunset or because of the UV rule
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Need help with sunscreen script

Post by waaren »

drwurn wrote: Wednesday 10 October 2018 19:03 I've made a dummy switch for the sunscreen for testing.
The dummy switch turned on this morning but didn't turn off after sunset or because of the UV rule
Can you check what the On / Off equivalent of "Open" is for your sunscreen and report back ?
What would also help is to add some log statements.
Thx
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
drwurn
Posts: 68
Joined: Sunday 10 June 2018 16:59
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Need help with sunscreen script

Post by drwurn »

waaren wrote: Wednesday 10 October 2018 22:04
drwurn wrote: Wednesday 10 October 2018 19:03 I've made a dummy switch for the sunscreen for testing.
The dummy switch turned on this morning but didn't turn off after sunset or because of the UV rule
Can you check what the On / Off equivalent of "Open" is for your sunscreen and report back ?
What would also help is to add some log statements.
Thx
Open = On and Close = Off.
The sunscreen isn't responding at all with the script, without the script the screen works as normal. Double checked the IDX's and they're right.

darksky.jpg
darksky.jpg (88.03 KiB) Viewed 3878 times

The log:
2018-10-10 22:18:00.410 Status: dzVents: Info: Sunscreen: ------ Start internal script: Zonnescherm:, trigger: every 1 minutes between 11:30 and 1 minute after 23:59 on 1/4-30/12
2018-10-10 22:18:00.446 Status: dzVents: Debug: Sunscreen: Processing device-adapter for Dummy Zonnescherm Forum: Switch device adapter
2018-10-10 22:18:00.447 Status: dzVents: Debug: Sunscreen: Processing device-adapter for Windsnelheid Assen: Wind device adapter
2018-10-10 22:18:00.449 Status: dzVents: Debug: Sunscreen: Processing device-adapter for UV Index Assen: UV device adapter
2018-10-10 22:18:00.450 Status: dzVents: Debug: Sunscreen: Processing device-adapter for Regen voorspelling Assen: Rain device
2018-10-10 22:18:00.450 Status: dzVents: Info: Sunscreen: ------ Finished Zonnescherm
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Need help with sunscreen script

Post by waaren »

drwurn wrote: Wednesday 10 October 2018 22:26
waaren wrote: Wednesday 10 October 2018 22:04
drwurn wrote: Wednesday 10 October 2018 19:03 I've made a dummy switch for the sunscreen for testing.
The dummy switch turned on this morning but didn't turn off after sunset or because of the UV rule
Can you check what the On / Off equivalent of "Open" is for your sunscreen and report back ?
What would also help is to add some log statements.
Thx
Open = On and Close = Off.
The sunscreen isn't responding at all with the script, without the script the screen works as normal. Double checked the IDX's and they're right.
At line 23 there is an extra space after the word Closed that does not belong there. Can you correct that and try again ?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
drwurn
Posts: 68
Joined: Sunday 10 June 2018 16:59
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Need help with sunscreen script

Post by drwurn »

waaren wrote: Wednesday 10 October 2018 22:38
drwurn wrote: Wednesday 10 October 2018 22:26
waaren wrote: Wednesday 10 October 2018 22:04
Can you check what the On / Off equivalent of "Open" is for your sunscreen and report back ?
What would also help is to add some log statements.
Thx
Open = On and Close = Off.
The sunscreen isn't responding at all with the script, without the script the screen works as normal. Double checked the IDX's and they're right.
At line 23 there is an extra space after the word Closed that does not belong there. Can you correct that and try again ?
Removed it but still don't work
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Need help with sunscreen script  [Solved]

Post by waaren »

drwurn wrote: Wednesday 10 October 2018 22:26 ... Removed it but still don't work
I Sent you a PM
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dendoba
Posts: 2
Joined: Tuesday 20 February 2018 15:27
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Need help with sunscreen script

Post by dendoba »

And? Did you manage to get it working?😊
remko2000
Posts: 165
Joined: Thursday 28 December 2017 14:38
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Broek op Langedijk
Contact:

Re: Need help with sunscreen script

Post by remko2000 »

good question: did you succeed???
Post Reply

Who is online

Users browsing this forum: HvdW and 1 guest