Address Aliasing? avoiding absolute addresses

Here is one nice finding with the new Ezlo environment. The LUA script below lets you toggle the state of a switch only knowing its name. No need to understand the nodes Ezlo iD address.

I had a pet peeve with Vera that using absolute addresses in scripts and scenes was a concern. If you replaced a ZWave device (faulty or a newer model) you had to go back and rework all your scripts and scenes as the replacement device would have a new absolute iD address. I believe with referencing nodes via their name you can avoid this absolute addressing problem of the past. Just delete the old one and when you include the new one use the identical name as before.

require "core"
local deviceName = "PlugSwitch"   -- name of device to control
local items = core.get_items()
if items then
    for _, item in ipairs(items) do
        if item.name == "switch" then
            local device = core.get_device(item.device_id)
            if device and device.name == deviceName then
                 core.set_item_value(  item.id, not( item.value), nil, nil, nil )
            end
        end
    end
end
3 Likes