Page 1 of 1

IKEA Styrbar script

Posted: Thursday 14 March 2024 7:32
by DewGew
I want to share my zigbee IKEA styrbar dimmer script. I use zigbee2MQTT and zigbee2MQTT plugin v3.2.0.
I tryed with MQTT AD but I got alot of on/off devices instead of 1 selector switch.

Code: Select all

-- Settings --
local dimmerIdx = 123 -- change to idx of your IKEA selector / dimmerswitch
local deviceIdx = 45  -- change to idx of you light/switch
local delta = 20      -- level steps for brightness
--
return
{
    on =
    {
        devices =
        {
            dimmerIdx,
        }
    },
    logging =
    {
        level = domoticz.LOG_DEBUG,
        marker = 'IKEA Styrbar / selector',
    },

--[[
    ** IKEA Styrbar Levelnames **
    'on' 
    'off'
    'brightness_move_up'
    'brightness_move_down'
    'brightness_stop'
    'arrow_left_click'
    'arrow_right_click'
    'arrow_left_hold'
    'arrow_right_hold'
    'arrow_left_release'
    'arrow_right_release'
    'Off'
]]--

    execute = function(dz, styrbar)

        local deviceToSwitch = dz.devices(deviceIdx)
        
        dz.log('Device ' .. styrbar.name .. ' updated. Last level was ' .. styrbar.lastLevel .. '; new level is ' .. styrbar.level .. ' (' .. styrbar.state .. ')', dz.LOG_DEBUG)
        
        dimlevel = deviceToSwitch.level

        if styrbar.state == 'on' then
            deviceToSwitch.switchOn()
        end
        if styrbar.state == 'brightness_move_up' then
            deviceToSwitch.dimTo(dimlevel + delta)
        end
        if styrbar.state == 'off' then 
            deviceToSwitch.switchOff()
        end
        if styrbar.state == 'brightness_move_down' then
            deviceToSwitch.dimTo(dimlevel-delta)
        end
    end
}

Re: IKEA Styrbar script

Posted: Thursday 14 March 2024 8:10
by waltervl
Something similar should also work with MQTT AD. You only have to trigger on all those button devices instead of the levels.

Re: IKEA Styrbar script

Posted: Friday 15 March 2024 18:21
by DewGew
waltervl wrote: Thursday 14 March 2024 8:10 Something similar should also work with MQTT AD. You only have to trigger on all those button devices instead of the levels.
Problem is that I have to add 11 dimmerIdx instead of 1

Re: IKEA Styrbar script

Posted: Friday 15 March 2024 19:41
by BazemanKM

Re: IKEA Styrbar script

Posted: Friday 15 March 2024 23:36
by waltervl
DewGew wrote: Friday 15 March 2024 18:21
waltervl wrote: Thursday 14 March 2024 8:10 Something similar should also work with MQTT AD. You only have to trigger on all those button devices instead of the levels.
Problem is that I have to add 11 dimmerIdx instead of 1
To add 11* IDX or 11* levelname in the script seems not a lot of difference....
Only saying that for the users of MQTT AD that that should not be a deal breaker to change to the plugin. Although I like the plugin way of working better too.