Page 1 of 1

Get UV values.

Posted: Monday 24 June 2019 12:26
by paul402
On the Weather tab I have all the usual items including UV levels.
I have several DzV scripts running to control and monitor lights, blinds/shutters, radio etc based on time of day and sunrise/sunset.
I want to add to the shutter control that when the UV level is >= x between certain hours then particular shutters should drop until time y.
But I can't seem to work out how to do it.
Can someone give me a clue please.

Re: Get UV values.

Posted: Monday 24 June 2019 12:57
by waaren
paul402 wrote: Monday 24 June 2019 12:26 On the Weather tab I have all the usual items including UV levels. Can someone give me a clue please.
I use the dzVents script below to control my sunscreen. One of the conditions I check is uv. Please have a look. Happy to help if something is not clear.

Code: Select all

-- sunScreen.lua

return 
{ 
    on = { timer = { 'every 12 minutes between 11:25 and 23:59 on 15/4-15/9' }},
    
    logging = { level = domoticz.LOG_ERROR, marker = 'Sunscreen' },
    
    execute = function(dz)

        local round = dz.utils.round
        -- devices
        local mySunscreen = dz.devices('Zonwering')
        local myWind = dz.devices('wind Rotterdam')
        local myTemperature = dz.devices('temperatuur Rotterdam')
        local myRain = dz.devices('neerslag Rotterdam')
        local myRainExpected = dz.devices('60 minute rain forecast')
        local myRadiation = dz.devices('Max.UV Rotterdam')
        local myMotion = dz.devices('Beweging buiten')
        local myLux = dz.devices('YoulessLux')
        local dumpConditions = true
        
        local function logWrite( msg, logLevel )
            dz.log( tostring(msg), logLevel or dz.LOG_FORCE)
        end

        local function logConditions(calledBy)
            logWrite("called by: " .. calledBy)
            logWrite("myTemperature.temperature                       " .. round(myTemperature.temperature,1 ))
            logWrite("myWind.speed                                    " .. round(myWind.speed,1 ))
            logWrite("myWind.gust                                     " .. round(myWind.gust,1 ))
            logWrite("myRain.rainRate                                 " .. tostring(myRain.rainRate))
            logWrite("myRainExpected.state                            " .. tostring(myRainExpected.state))
            logWrite("myRadiation.uv                                  " .. round(myRadiation.uv,1 ))
            logWrite("dz.time.matchesRule('at 12:00-19:00')           " .. tostring(dz.time.matchesRule('at 12:00-19:00') ))
            logWrite("dz.time.matchesRule('at 23:00-01:00')           " .. tostring(dz.time.matchesRule('at 23:00-01:00')))
            logWrite("dz.time.matchesRule('at nighttime')             " .. tostring(dz.time.matchesRule('at nighttime')))
            logWrite("mySunscreen.lastUpdate.minutesAgo               " .. tostring(mySunscreen.lastUpdate.minutesAgo ))
            logWrite("myMotion.lastUpdate.minutesAgo                  " .. tostring(myMotion.lastUpdate.minutesAgo))
            logWrite("myLux.lux                                       " .. round(myLux.lux,1 ))
        end
        
        if 
        ( myTemperature.temperature > 18 and
          myWind.speed < 6 and 
          myWind.gust < 17 and
          tonumber(myRain.rainRate) < 0.2 and
          tonumber(myRainExpected.state) < 1 and
          myRadiation.uv > 4 and
          dz.time.matchesRule('at 12:00-19:00') and
          mySunscreen.lastUpdate.minutesAgo > 30 and 
          myMotion.lastUpdate.minutesAgo > 5 and
          myLux.lux > 2200 
        )   then   
                mySunscreen.switchOn()
                if dumpConditions then logConditions('open') end
        elseif  
        (  dz.time.matchesRule('at 23:00-01:00') or
           myWind.speed > 5  or 
           myWind.gust > 16 or
           tonumber(myRain.rainRate) > 0.1 or
           dz.time.matchesRule('at nighttime') or
           tonumber(myRainExpected.state) >1 or 
           myLux.lux < 400 or 
           myTemperature.temperature < 16 
         )  then
                mySunscreen.switchOff()
                if dumpConditions then logConditions('close') end
        else
                if dumpConditions then logConditions('neither') end
        end
    end
}

Re: Get UV values.

Posted: Monday 24 June 2019 15:18
by paul402
Thanks! I see now that I had just used my "Label Name" rather than "local uv_value=outside_sensor.uv".
I had used it correctly for the other sensors!
The leg up is much appreciated. Sometimes you miss the little things.