Need help with sunscreen script

Easy to use, 100% Lua-based event scripting framework.
Post Reply
drwurn
Posts: 42
Joined: Sunday 10 June 2018 16:59
Target OS: Raspberry Pi
Domoticz version:
Contact:

Need help with sunscreen script

Post by drwurn » 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.

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: 1350
Joined: Tuesday 03 January 2017 15:18
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Need help with sunscreen script

Post by waaren » 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
}
Raspberry (debian stretch via berryboot on Synology DS916+) , Domoticz (almost) latest Beta, , dzVents 2.6, RFLink, RFXtrx433e, P1, Youless, Harmony, Hue, Yeelight, Xiaomi, HomeWizard, Zwave, Amazon echo

drwurn
Posts: 42
Joined: Sunday 10 June 2018 16:59
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Need help with sunscreen script

Post by drwurn » Tuesday 09 October 2018 23:48

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: 1350
Joined: Tuesday 03 January 2017 15:18
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Need help with sunscreen script

Post by waaren » Wednesday 10 October 2018 0:00

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
}
Raspberry (debian stretch via berryboot on Synology DS916+) , Domoticz (almost) latest Beta, , dzVents 2.6, RFLink, RFXtrx433e, P1, Youless, Harmony, Hue, Yeelight, Xiaomi, HomeWizard, Zwave, Amazon echo

drwurn
Posts: 42
Joined: Sunday 10 June 2018 16:59
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Need help with sunscreen script

Post by drwurn » 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

User avatar
waaren
Posts: 1350
Joined: Tuesday 03 January 2017 15:18
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Need help with sunscreen script

Post by waaren » 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
Raspberry (debian stretch via berryboot on Synology DS916+) , Domoticz (almost) latest Beta, , dzVents 2.6, RFLink, RFXtrx433e, P1, Youless, Harmony, Hue, Yeelight, Xiaomi, HomeWizard, Zwave, Amazon echo

drwurn
Posts: 42
Joined: Sunday 10 June 2018 16:59
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Need help with sunscreen script

Post by drwurn » 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.

darksky.jpg
darksky.jpg (88.03 KiB) Viewed 208 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: 1350
Joined: Tuesday 03 January 2017 15:18
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Need help with sunscreen script

Post by waaren » Wednesday 10 October 2018 22:38

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 ?
Raspberry (debian stretch via berryboot on Synology DS916+) , Domoticz (almost) latest Beta, , dzVents 2.6, RFLink, RFXtrx433e, P1, Youless, Harmony, Hue, Yeelight, Xiaomi, HomeWizard, Zwave, Amazon echo

drwurn
Posts: 42
Joined: Sunday 10 June 2018 16:59
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Need help with sunscreen script

Post by drwurn » Wednesday 10 October 2018 22:45

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: 1350
Joined: Tuesday 03 January 2017 15:18
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Need help with sunscreen script

Post by waaren » Thursday 11 October 2018 5:32

drwurn wrote:
Wednesday 10 October 2018 22:26
... Removed it but still don't work
I Sent you a PM
Raspberry (debian stretch via berryboot on Synology DS916+) , Domoticz (almost) latest Beta, , dzVents 2.6, RFLink, RFXtrx433e, P1, Youless, Harmony, Hue, Yeelight, Xiaomi, HomeWizard, Zwave, Amazon echo

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests