Script modification for switching devices by rain

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

Moderator: leecollings

Post Reply
User avatar
madpatrick
Posts: 636
Joined: Monday 26 December 2016 12:17
Target OS: Linux
Domoticz version: 2024.7
Location: Netherlands
Contact:

Script modification for switching devices by rain

Post by madpatrick »

Hi,

I need a bit of help to modify this script which i've found here : https://domoticaboard.nl/index.php?topic=44.0
The script is running, but i like to trigger more devices then the one now
How can i add a list of devices that will be switch by the script

So far i know you can do it with the funcrion "pairs"

Code: Select all

-- Define all the sensors which needs to be considered for the sunscreen to close
local sensors = {
    rain = {
        active = true,
        device = 'RegenData',
        closeRule = function(device)
            return device.rainRate > 0
        end
    }
}

local sunscreenDevice   = 'TestSwitch'      -- Define the name of your sunscreen device
local dryRun            = false             -- Enable dry run mode to test the sunscreen script without actually activating the sunscreen


return {
    active = true,
    on = {
        --timer = {'every minute'},
        devices = {290},
    },
    logging = {
        level = domoticz.LOG_DEBUG,
        marker = 'Sunscreen'
    },
    execute = function(domoticz)

        local function switchOn(sunscreen)
            if (sunscreen.state == 'Off') then
                if (not dryRun) then
                sunscreen.switchOn()
                --domoticz.notify('Sunscreen', message)
                end
                domoticz.log(message, domoticz.LOG_INFO)
            end
        end

        local function switchOff(sunscreen)
            if (sunscreen.state == 'On') then
                if (not dryRun) then
                sunscreen.switchOff()
                --domoticz.notify('Sunscreen', message)
                end
                domoticz.log(message, domoticz.LOG_INFO)
            end
        end

        local sunscreen = domoticz.devices(sunscreenDevice)

        -- 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

                    switchOn(sunscreen, sensorType .. ' treshold exceeded, Sunscreen up')

                    domoticz.log(sensorType .. ' treshold exceeded', domoticz.LOG_DEBUG)
                    -- Return early when we exeed any tresholds
                    return
                end
            else
                domoticz.log('Sensor not active skipping: ' .. sensorType, domoticz.LOG_DEBUG)
            end
        end

    end
}
-= HP server GEN8 Xeon(R) E3-1220L_V2 -=- OZW -=- Toon2 (rooted) -=- Domoticz v2024.7 -=- Dashticz v3.12b on Tab8" =-
User avatar
waltervl
Posts: 5148
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Script modification for switching devices by rain

Post by waltervl »

You can also make a Domoticz group or scene, add the devices you want to switch to the group and switch the group by the script.

Else you have to change the switching(sunscreen) function....
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
User avatar
madpatrick
Posts: 636
Joined: Monday 26 December 2016 12:17
Target OS: Linux
Domoticz version: 2024.7
Location: Netherlands
Contact:

Re: Script modification for switching devices by rain

Post by madpatrick »

Thanks. Maing a group was also the easiest solution i could think of.
It is working !
-= HP server GEN8 Xeon(R) E3-1220L_V2 -=- OZW -=- Toon2 (rooted) -=- Domoticz v2024.7 -=- Dashticz v3.12b on Tab8" =-
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest