dzVents script - Execute setting multiple devices  [Solved]

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

Moderator: leecollings

Post Reply
Rs3b
Posts: 4
Joined: Friday 18 August 2017 12:22
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

dzVents script - Execute setting multiple devices

Post by Rs3b »

Hello,

I'm trying on a specific time set the setpoints of multiple devices at once to a certain value. I notice only the first device is changed after executing the script, the other ones are unchanged. The setpoints are on Popp thermostats.

return {
on = {
timer = {
'at 20:55'
}
},
execute = function(domoticz)
domoticz.devices('Radiator Setpoint N1').updateSetPoint(12)
domoticz.devices('Radiator Setpoint N2').updateSetPoint(12)
domoticz.devices('Radiator Setpoint N3').updateSetPoint(12)
domoticz.devices('Radiator Setpoint W1').updateSetPoint(12)
domoticz.devices('Radiator Setpoint Z1').updateSetPoint(12)
end
}

I also tried using a wild-card, but it doesn't recognize the device this way: domoticz.devices('Radiator Setpoint*').updateSetPoint(12).

As I understand it I cannot use group or scene, because scene is for lights (right?) - at least I do not see the Popp devices when creating group or scene in the add devices dropdown.

Anyone can give me a hint?

Thanks!
Rs3b
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: dzVents script - Execute setting multiple devices  [Solved]

Post by waaren »

Rs3b wrote: Saturday 19 January 2019 21:44 I'm trying on a specific time set the setpoints of multiple devices at once to a certain value. I notice only the first device is changed after executing the script, the other ones are unchanged. The setpoints are on Popp thermostats.
Can you try this and look at the log ?

Code: Select all

return {
            on = { 
                    timer   = { 'at 23:25'  },
                 },
        
        logging =   {
                        level           =   domoticz.LOG_DEBUG,
                        marker          =   setSetPoints
                    },
                 
     execute = function(dz)
        
        local function logWrite(str,level)
            dz.log(tostring(str),level or dz.LOG_DEBUG)
        end

        local N1 = dz.devices('Radiator Setpoint N1')
        local N2 = dz.devices('Radiator Setpoint N2')
        local N3 = dz.devices('Radiator Setpoint N3')
        local W1 = dz.devices('Radiator Setpoint W1')
        local Z1 = dz.devices('Radiator Setpoint Z1')
        
        local setPoints= { N1,N2,N3,W1,Z1}
        
        for i = 1,#setPoints do
            setPoints[i].updateSetPoint(12)
            local rawData = ""
            for j = 1,#setPoints[i].rawData do
                rawData = rawData .. setPoints[i].rawData[j] .. "; "
            end
            logWrite(setPoints[i].name .. "; type: " .. setPoints[i].deviceType .. "; subtype: " .. setPoints[i].deviceSubType .. "; nvalue: " .. setPoints[i].nValue .. "; rawData: " .. rawData)
        end
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Rs3b
Posts: 4
Joined: Friday 18 August 2017 12:22
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: dzVents script - Execute setting multiple devices

Post by Rs3b »

Hello waaren,

Many thanks for your example code, it works perfectly!

The log:

Code: Select all

2019-01-20 11:17:00.209 Status: dzVents: Info: ------ Start external script: test.lua:, trigger: at 11:17
2019-01-20 11:17:00.229 Status: dzVents: Debug: Processing device-adapter for Radiator Setpoint N1: Thermostat setpoint device adapter
2019-01-20 11:17:00.230 Status: dzVents: Debug: Processing device-adapter for Radiator Setpoint N2: Thermostat setpoint device adapter
2019-01-20 11:17:00.231 Status: dzVents: Debug: Processing device-adapter for Radiator Setpoint N3: Thermostat setpoint device adapter
2019-01-20 11:17:00.231 Status: dzVents: Debug: Processing device-adapter for Radiator Setpoint W1: Thermostat setpoint device adapter
2019-01-20 11:17:00.232 Status: dzVents: Debug: Processing device-adapter for Radiator Setpoint Z1: Thermostat setpoint device adapter
2019-01-20 11:17:00.232 Status: dzVents: Debug: Constructed timed-command: 12
2019-01-20 11:17:00.232 Status: dzVents: Debug: Radiator Setpoint N1; type: Thermostat; subtype: SetPoint; nvalue: 0; rawData: 20.00;
2019-01-20 11:17:00.232 Status: dzVents: Debug: Constructed timed-command: 12
2019-01-20 11:17:00.233 Status: dzVents: Debug: Radiator Setpoint N2; type: Thermostat; subtype: SetPoint; nvalue: 0; rawData: 20.00;
2019-01-20 11:17:00.233 Status: dzVents: Debug: Constructed timed-command: 12
2019-01-20 11:17:00.233 Status: dzVents: Debug: Radiator Setpoint N3; type: Thermostat; subtype: SetPoint; nvalue: 0; rawData: 20.00;
2019-01-20 11:17:00.233 Status: dzVents: Debug: Constructed timed-command: 12
2019-01-20 11:17:00.233 Status: dzVents: Debug: Radiator Setpoint W1; type: Thermostat; subtype: SetPoint; nvalue: 0; rawData: 20.00;
2019-01-20 11:17:00.233 Status: dzVents: Debug: Constructed timed-command: 12
2019-01-20 11:17:00.233 Status: dzVents: Debug: Radiator Setpoint Z1; type: Thermostat; subtype: SetPoint; nvalue: 0; rawData: 20.00;
2019-01-20 11:17:00.233 Status: dzVents: Info: ------ Finished test.lua
It also pointed my to an error in my code, first time I ran the script it got:

Code: Select all

2019-01-20 11:04:00.601 Status: dzVents: Debug: Processing device-adapter for Radiator Setpoint N1: Thermostat setpoint device adapter
2019-01-20 11:04:00.601 Status: dzVents: Error (2.4.6): There is no device with that name or id: Radiator Setpoint N2
Turns out I named the setpoint "Radiator SetPoint N2"...I put in a capital P only in this setpoint name. It was the second one in my script, so I tested my original script, and this also ran fine after changing the P into p. Lua is case-sensitive... silly me!!! Still in the learning lua phase... :oops:

I may be overasking, but if I want to use domoticz.devices().forEach(..) using an arry, how would the syntax be in that case?

Thanks,
rs3b
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: dzVents script - Execute setting multiple devices

Post by waaren »

Rs3b wrote: Sunday 20 January 2019 11:41 If I want to use domoticz.devices().forEach(..) using an arry, how would the syntax be in that case?

Thanks,
rs3b
I am not sure what you want/ The example code I posted does iterate over the array of devices.

If your intention is to set the setPoints of all relevant devices in your domoticz environment you could this.

Code: Select all

return {
            on  =   { 
                        timer   = { "every 1 minutes"  }
                    }, 
        
        logging =   {   
                        level   =   domoticz.LOG_ERROR,                   
                        marker  =   "filter "
                   },
     
    execute = function(dz, item)
        spaces = " " ; for i=1,25 do spaces = spaces .. " " end
        
        local function logWrite(str,level)
            dz.log(tostring(str),level or dz.LOG_DEBUG)
        end
        
        dz.devices().filter(function(dv)                         -- Chain filter and forEach
            return (dv.deviceType == "Thermostat" and dv.deviceSubType == "SetPoint" )
        end).forEach(function(dv)
            logWrite((dv.name .. spaces ):sub(1,25) .. dv.setPoint,dz.LOG_FORCE)
            -- dv.updateSetPoint(12)                                                   -- Setting all setPoints in your system to 12
        end)
    
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest