Page 1 of 1

Radiator heads spirit

Posted: Thursday 19 November 2020 14:19
by laco
Hi, I need help creating a simple script to bulk change all the radiator spirit heads.

I have created a virtual switch:

Image
Image

Radiator heads:

Image

Image

Image

Image

If the value on the virtual switch changes, then change the value on all thermostats in bulk.

Re: Radiator heads spirit

Posted: Thursday 19 November 2020 15:47
by waaren
laco wrote: Thursday 19 November 2020 14:19 I need help creating a simple script to bulk change all the radiator spirit heads.
If the value on the virtual switch changes, then change the value on all thermostats in bulk.
It's not completely clear what type of devices these are (probably also a language thing) and that information is required to be able to advise if it is possible or not.

Can you run below script once and share the complete loglines

Code: Select all

return 
{
    on = 
    {
        timer = 
        {
            'at 15:09', -- change to time you want to dump the devices
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG,
        marker = 'multiple thermostats',
    },

    execute = function(dz)
        local selector = dz.devices('Kúrenite firma') 
        local thermostat = dz.devices('Termostat firma chodba') 

        local function dumpAttributes(dv)
            dz.log('--------------------------',dz.LOG_FORCE) 
            dz.log(dv.idx .. ':' .. dv.name .. ' : type, subType   -> ' .. dv.deviceType .. ', '.. tostring(dv.deviceSubType),dz.LOG_FORCE)
            dz.log(dv.idx .. ':' .. dv.name .. ' : switchTypeValue -> ' .. dv.switchTypeValue ,dz.LOG_FORCE)
            dz.log(dv.idx .. ':' .. dv.name .. ' : adapters        -> ' .. dz.utils._.str(dv._adapters),dz.LOG_FORCE)
            dz.log(dv.idx .. ':' .. dv.name .. ' : rawData         -> ' .. dz.utils._.str(dv.rawData),dz.LOG_FORCE)
            dz.log(dv.idx .. ':' .. dv.name .. ' : hwType          -> ' .. dv.hardwareType .. ', ' .. dv.hardwareTypeValue,dz.LOG_FORCE)
            
        end
        
       dumpAttributes(selector)
       dumpAttributes(thermostat)

    end
}

Re: Radiator heads spirit

Posted: Thursday 19 November 2020 16:30
by laco

Code: Select all

2020-11-19 16:29:00.476 Status: dzVents: Info: multiple thermostats: ------ Start internal script: Script #TEST:, trigger: "at 16:29"
2020-11-19 16:29:00.488 Status: dzVents: Debug: multiple thermostats: Processing device-adapter for Termostat firma chodba: Z-Wave mode type device adapter
2020-11-19 16:29:00.488 Status: dzVents: !Info: multiple thermostats: --------------------------
2020-11-19 16:29:00.488 Status: dzVents: Info: multiple thermostats: ------ Finished Script #TEST
2020-11-19 16:29:00.476 Error: dzVents: Error: (3.0.16) multiple thermostats: There is no device with that name or id: Kúrenite firma
2020-11-19 16:29:00.488 Error: dzVents: Error: (3.0.16) multiple thermostats: An error occurred when calling event handler Script #TEST
2020-11-19 16:29:00.488 Error: dzVents: Error: (3.0.16) multiple thermostats: ...z/var/scripts/dzVents/generated_scripts/Script #TEST.lua:23: attempt to index a nil value

Re: Radiator heads spirit

Posted: Thursday 19 November 2020 17:07
by waaren
laco wrote: Thursday 19 November 2020 16:30

Code: Select all

There is no device with that name or id: Kúrenite firma
Probably I mistypes one of the device names. Please correct it and run again.

Re: Radiator heads spirit

Posted: Thursday 19 November 2020 17:27
by laco

Code: Select all

2020-11-19 17:25:00.470 Status: dzVents: Info: multiple thermostats: ------ Start internal script: Script #TEST:, trigger: "at 17:25"
2020-11-19 17:25:00.471 Status: dzVents: Debug: multiple thermostats: Processing device-adapter for Kúrenie firma: Switch device adapter
2020-11-19 17:25:00.472 Status: dzVents: Debug: multiple thermostats: Processing device-adapter for Termostat firma chodba: Z-Wave mode type device adapter
2020-11-19 17:25:00.472 Status: dzVents: !Info: multiple thermostats: --------------------------
2020-11-19 17:25:00.472 Status: dzVents: !Info: multiple thermostats: 564:Kúrenie firma : type, subType -> Light/Switch, Selector Switch
2020-11-19 17:25:00.473 Status: dzVents: !Info: multiple thermostats: 564:Kúrenie firma : switchTypeValue -> 18
2020-11-19 17:25:00.473 Status: dzVents: !Info: multiple thermostats: 564:Kúrenie firma : adapters -> {"Switch device adapter"}
2020-11-19 17:25:00.473 Status: dzVents: !Info: multiple thermostats: 564:Kúrenie firma : rawData -> {"20"}
2020-11-19 17:25:00.473 Status: dzVents: !Info: multiple thermostats: 564:Kúrenie firma : hwType -> Dummy (Does nothing, use for virtual switches only), 15
2020-11-19 17:25:00.473 Status: dzVents: !Info: multiple thermostats: --------------------------
2020-11-19 17:25:00.473 Status: dzVents: !Info: multiple thermostats: 700:Termostat firma chodba : type, subType -> General, Thermostat Mode
2020-11-19 17:25:00.473 Status: dzVents: !Info: multiple thermostats: 700:Termostat firma chodba : switchTypeValue -> 0
2020-11-19 17:25:00.473 Status: dzVents: !Info: multiple thermostats: 700:Termostat firma chodba : adapters -> {"Z-Wave mode type device adapter"}
2020-11-19 17:25:00.473 Status: dzVents: !Info: multiple thermostats: 700:Termostat firma chodba : rawData -> {}
2020-11-19 17:25:00.473 Status: dzVents: !Info: multiple thermostats: 700:Termostat firma chodba : hwType -> OpenZWave USB, 21
2020-11-19 17:25:00.473 Status: dzVents: Info: multiple thermostats: ------ Finished Script #TEST
2020-11-19 17:25:00.471 Error: dzVents: Error: (3.0.16) multiple thermostats: Multiple items found for Kúrenie firma (device). Please make sure your names are unique or use ids instead.

Re: Radiator heads spirit

Posted: Thursday 19 November 2020 17:50
by waaren
laco wrote: Thursday 19 November 2020 17:27

Code: Select all

2020-11-19 17:25:00.471 Error: dzVents: Error: (3.0.16) multiple thermostats: Multiple items found for Kúrenie firma (device). Please make sure your names are unique or use ids instead.
Any idea why you see this error? Do you have have devices with the duplicate names in the same system?
'
I added two attributes to the list, they are required to ensure a working script can be created.

Code: Select all

return
{
    on =
    {
        timer =
        {
            'at 17:51', -- change to time you want to dump the devices
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG, -- set to domoticz.LOG_ERROR when all ok
        marker = 'multiple thermostats',
    },

    execute = function(dz)
        local selector = dz.devices(564)
        local thermostat = dz.devices(700)

        local function dumpAttributes(dv)
            dz.log(dv.idx .. ':' .. dv.name .. ' : type, subType   -> ' .. dv.deviceType .. ', '.. tostring(dv.deviceSubType),dz.LOG_FORCE)
            dz.log(dv.idx .. ':' .. dv.name .. ' : switchTypeValue -> ' .. dv.switchTypeValue ,dz.LOG_FORCE)
            dz.log(dv.idx .. ':' .. dv.name .. ' : adapters        -> ' .. dz.utils._.str(dv._adapters),dz.LOG_FORCE)
            dz.log(dv.idx .. ':' .. dv.name .. ' : rawData         -> ' .. dz.utils._.str(dv.rawData),dz.LOG_FORCE)
            dz.log(dv.idx .. ':' .. dv.name .. ' : hwType          -> ' .. dv.hardwareType .. ', ' .. dv.hardwareTypeValue,dz.LOG_FORCE)
            dz.log(dv.idx .. ':' .. dv.name .. ' : levelNames      -> ' .. dz.utils._.str(dv.levelNames),dz.LOG_FORCE)
            dz.log(dv.idx .. ':' .. dv.name .. ' : modes           -> ' .. dz.utils._.str(dv.modes),dz.LOG_FORCE)
        end

       dumpAttributes(selector)
       dumpAttributes(thermostat)

    end
}

Re: Radiator heads spirit

Posted: Thursday 19 November 2020 18:03
by laco

Code: Select all

2020-11-19 18:02:00.415 Status: dzVents: Info: multiple thermostats: ------ Start internal script: Script #TEST:, trigger: "at 18:02"
2020-11-19 18:02:00.415 Status: dzVents: Debug: multiple thermostats: Processing device-adapter for Kúrenie firma: Switch device adapter
2020-11-19 18:02:00.416 Status: dzVents: Debug: multiple thermostats: Processing device-adapter for Termostat firma chodba: Z-Wave mode type device adapter
2020-11-19 18:02:00.416 Status: dzVents: !Info: multiple thermostats: --------------------------
2020-11-19 18:02:00.416 Status: dzVents: !Info: multiple thermostats: 564:Kúrenie firma : type, subType -> Light/Switch, Selector Switch
2020-11-19 18:02:00.417 Status: dzVents: !Info: multiple thermostats: 564:Kúrenie firma : switchTypeValue -> 18
2020-11-19 18:02:00.417 Status: dzVents: !Info: multiple thermostats: 564:Kúrenie firma : adapters -> {"Switch device adapter"}
2020-11-19 18:02:00.417 Status: dzVents: !Info: multiple thermostats: 564:Kúrenie firma : rawData -> {"20"}
2020-11-19 18:02:00.417 Status: dzVents: !Info: multiple thermostats: 564:Kúrenie firma : hwType -> Dummy (Does nothing, use for virtual switches only), 15
2020-11-19 18:02:00.417 Status: dzVents: !Info: multiple thermostats: --------------------------
2020-11-19 18:02:00.417 Status: dzVents: !Info: multiple thermostats: 700:Termostat firma chodba : type, subType -> General, Thermostat Mode
2020-11-19 18:02:00.417 Status: dzVents: !Info: multiple thermostats: 700:Termostat firma chodba : switchTypeValue -> 0
2020-11-19 18:02:00.417 Status: dzVents: !Info: multiple thermostats: 700:Termostat firma chodba : adapters -> {"Z-Wave mode type device adapter"}
2020-11-19 18:02:00.417 Status: dzVents: !Info: multiple thermostats: 700:Termostat firma chodba : rawData -> {}
2020-11-19 18:02:00.417 Status: dzVents: !Info: multiple thermostats: 700:Termostat firma chodba : hwType -> OpenZWave USB, 21
2020-11-19 18:02:00.417 Status: dzVents: Info: multiple thermostats: ------ Finished Script #TEST

Re: Radiator heads spirit

Posted: Thursday 19 November 2020 18:51
by laco

Code: Select all

2020-11-19 18:51:00.228 Status: dzVents: Info: multiple thermostats: ------ Start internal script: Script #TEST:, trigger: "at 18:51"
2020-11-19 18:51:00.239 Status: dzVents: Debug: multiple thermostats: Processing device-adapter for Kúrenie firma: Switch device adapter
2020-11-19 18:51:00.240 Status: dzVents: Debug: multiple thermostats: Processing device-adapter for Termostat firma chodba: Z-Wave mode type device adapter
2020-11-19 18:51:00.240 Status: dzVents: !Info: multiple thermostats: 564:Kúrenie firma : type, subType -> Light/Switch, Selector Switch
2020-11-19 18:51:00.240 Status: dzVents: !Info: multiple thermostats: 564:Kúrenie firma : switchTypeValue -> 18
2020-11-19 18:51:00.240 Status: dzVents: !Info: multiple thermostats: 564:Kúrenie firma : adapters -> {"Switch device adapter"}
2020-11-19 18:51:00.241 Status: dzVents: !Info: multiple thermostats: 564:Kúrenie firma : rawData -> {"20"}
2020-11-19 18:51:00.241 Status: dzVents: !Info: multiple thermostats: 564:Kúrenie firma : hwType -> Dummy (Does nothing, use for virtual switches only), 15
2020-11-19 18:51:00.241 Status: dzVents: !Info: multiple thermostats: 564:Kúrenie firma : levelNames -> {"Off", "HeatEco", "Heat", "FullPower"}
2020-11-19 18:51:00.241 Status: dzVents: !Info: multiple thermostats: 564:Kúrenie firma : modes -> nil
2020-11-19 18:51:00.241 Status: dzVents: !Info: multiple thermostats: 700:Termostat firma chodba : type, subType -> General, Thermostat Mode
2020-11-19 18:51:00.241 Status: dzVents: !Info: multiple thermostats: 700:Termostat firma chodba : switchTypeValue -> 0
2020-11-19 18:51:00.241 Status: dzVents: !Info: multiple thermostats: 700:Termostat firma chodba : adapters -> {"Z-Wave mode type device adapter"}
2020-11-19 18:51:00.241 Status: dzVents: !Info: multiple thermostats: 700:Termostat firma chodba : rawData -> {}
2020-11-19 18:51:00.241 Status: dzVents: !Info: multiple thermostats: 700:Termostat firma chodba : hwType -> OpenZWave USB, 21
2020-11-19 18:51:00.241 Status: dzVents: !Info: multiple thermostats: 700:Termostat firma chodba : levelNames -> nil
2020-11-19 18:51:00.241 Status: dzVents: !Info: multiple thermostats: 700:Termostat firma chodba : modes -> {"Off", "Heat", "Heat Eco", "Full Power", "Manufacturer Specific"}
2020-11-19 18:51:00.241 Status: dzVents: Info: multiple thermostats: ------ Finished Script #TEST

Re: Radiator heads spirit

Posted: Thursday 19 November 2020 21:22
by waaren
Can you try this?

Code: Select all

return 
{
    on = 
    {
        devices = 
        {
            'Kúrenie firma',
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG, -- set to domoticz.LOG_ERROR when all ok
        marker = 'master themostat',
    },

    execute = function(dz, item)
        local targetThermostats =
        {
            'chodba',
            'predajña',
            'obchod',
        }

        local modes =
        {
            Off         = 'Off',
            HeatEco     = 'Heat Eco', 
            Heat        = 'Heat',
            FullPower   = 'Full Power',
        }
        
        for _, dv in ipairs(targetThermostats) do
            dz.devices('Termostat firma ' .. dv).updateMode(modes[item.levelName])
            dz.log('dz.devices("Termostat firma ' .. dv ..'").updateMode("' .. modes[item.levelName] .. '")', dz.LOG_DEBUG)
        end
    end
}

Re: Radiator heads spirit  [Solved]

Posted: Friday 20 November 2020 14:06
by laco
Works great! Good job, thank you very much.