Dynamically set parameters for all Z-wave devices of type X

Hi!
First post and HA-newbie so be nice :blush:
Running Home Assistant OS.

So I’m a longtime Open Z-Wave and Domoticz user that finally decided to give HA a try. While I do love how beautiful and easy HA is to use, I’ve always figured that the “plugin”-way and “easyness” comes at a price of increased limitations of how I can program and control what happens. This can be pure ignorence on my part, however.

I’m currently trying to both migrate my devices and also my automations but find the “automations” lacking in the sense that you essentially write configurations rather that code, logic or scripts.

Please advice if / how the following can be acheived in Home Assistant:

I want to automatically change the value of a parameter of all Z-wave devices of one or many types. I also want to do this “dynamically” in the sense that I dont want to update or maintain a configuration-file whenever I add or remove a device of that same type to the network. (Here I currently feel that “automations” lack a bit - it’s not really an “automation” if I have to manually maintain a configuration file imo)

In Domoticz I currently solve this by utilizing it’s web API. Whenever a trigger occurs (my case, change in electricity price) I query all the Z-Wave devices currently in Domoticz. I then store the Z-wave Device Id for all devices that have a certain type. In the next API call I set the desiered parameter to the desiered value for all those Device Ids.

Quite simple and straight forward - this way I dont have to create or update “automations” every time I add another Z-wave device to the network. How can the same be achieved in Home Assistant?



To maybe further clarify what I want to do, heres the important parts of my current LUA-script in Domoticz:
A potential solution does in no way have to be in LUA, pretty much any other programming or scripting language / syntax is preferred. LUA is just the prefered language for Domoticz automations.

-- Variables to keep track of what Z-wave Device Type script should handle "dynamically"
local wallplugProductTypeId = '0x0602'
local dimmerProductTypeId = '0x1c01'
local switchProductTypeId = '0x1b01'

local function getDevices(domoticz) -- Get _all_ Zwave Devices
			domoticz.openURL({
				url = 'https://localhost:8080/json.htm?type=openzwavenodes&idx=2',
				method = 'GET',
				callback = 'getZwaveDevices'
			}) 
end

local function getDeviceInfo(jsonData) -- Filter out the device types we want and store its Ids in tables
    local deviceCount = getTableLength(jsonData.result)
    
    local wallplugIds = {}
    local dimmerIds = {}
    local switchIds = {}
    
    for i = 1,deviceCount,1
        do
            local device = jsonData.result[i]
            if (device.Product_type == wallplugProductTypeId) then   
                table.insert(wallplugIds,device.idx)
            elseif (device.Product_type == dimmerProductTypeId) then
                table.insert(dimmerIds,device.idx)
            elseif (device.Product_type == switchProductTypeId) then
                table.insert(switchIds,device.idx)
            end
    end
    return wallplugIds, dimmerIds, switchIds
end

local function setWallplugColor(domoticz, id, color) -- Change Zwave parameter 41 to the value of 'color' for the given Ids 
        domoticz.openURL({
    	url = 'https://localhost:8080/json.htm?type=command&param=applyzwavenodeconfig&idx='.. id ..'&valuelist=41_' .. color,
    	method = 'GET'
    })
end

That’s cool! I’m finding that I have use cases for similar things. So very interested in the solve.

You can write python and create an integration that could do this, it is a code development activity. From the script perspective:

Impediments. AFAIK, there is no way to enumerate the devices in a script.

Here’s an idea that could work.

  1. Create a switch template for one of your devices. When you turn it on, it sets the config parameter to a value, when off sets the config parameter to the other value.
  2. Convert this into a package, use a technique similar to what i do for zwave health to autogen the packages for the other devices. GitHub - PeteRager/hass_templates
  3. Put all the switches into a group
  4. The mainline automation turns the group on or off.

This post where I had a question outline some of the ways to get config current value which you may need for the template or you can track state with a boolean.

Thanks for your input Pete!
Python is probably the way to go, but writing an integration for this seems overkill. Or maybe I need to learn more about what constitutes an “integration”.

Your suggestion about using switch templates unfortunately still means I have to manually add future devices into a group and then manage and maintain configuration, which is what I’d like to avoid.
Further, I dont think the switch template would work in my specific case. It’s probably a good suggestion if you have one or two different config parameter values to alternate between! But unfortunately in my case I have a total of (3 different device types times 3 values=) 9 values.

I will probably have to look further into how to write an “integration” in HA even if that seems a bit “heavy handed” to me in comparison to just loop through a couple of devices and update its values.

Look at this link for an example.

Everytime I add a device there is stuff to do, if you automate the config Gen this then all this config is auto created anyway.

1 Like