Hey there, itâs me again. ^^
I would like to replicate your example as I also use STYRBAR remotes. I have two main differences:
- I connect the remote via the deconz binding and not via zigbee2mqtt
- The number of lights which get controlled by a remote is dynamic. Currently I have 2 remotes. Remote âAâ controls 1 light and remote âBâ for which I brought some items below controls 3 lights. In the future I will have more remotes maybe which either control 1 or multiple lightsâŠ
I could get it already running by 50%. Means: I can switch on/off the lights and change the color temperature. However, none of the fading features work. Both for brightness and for changing the color temperature.
Letâs start with the items, 3 lamps combined in one group. The semantic model only knows all lamps as one group:
// *** Deckenlampen Hobbyraum ***
Group Deckenlampen_Hobbyraum
(Ort_Hobbyraum)
["Lightbulb"]
Group:Switch Deckenlampe_Hobbyraum_Einschaltstatus
(Deckenlampen_Hobbyraum)
["Control", "Light"]
Group:Dimmer Deckenlampe_Hobbyraum_Helligkeit
(Deckenlampen_Hobbyraum)
["Control", "Level"]
Group:Number Deckenlampe_Hobbyraum_Farbtemperatur
(Deckenlampen_Hobbyraum)
["Control", "ColorTemperature"]
// Deckenlampe Hobbyraum Buecherregal
Group Deckenlampe_Hobbyraum_Buecherregal_Homekit
"Deckenlampe Hobbyraum BĂŒcherregal Homekit"
{
homekit="Lighting"
}
Switch Deckenlampe_Hobbyraum_Buecherregal_Einschaltstatus
"Einschaltstatus Deckenlampe Hobbyraum BĂŒcherregal [MAP(de.map):%s]"
(Deckenlampe_Hobbyraum_Buecherregal_Homekit, Deckenlampe_Hobbyraum_Einschaltstatus)
{
homekit="Lighting.OnState"
}
Dimmer Deckenlampe_Hobbyraum_Buecherregal_Helligkeit
"Helligkeit Deckenlampe Hobbyraum BĂŒcherregal [%d]"
(Deckenlampe_Hobbyraum_Buecherregal_Homekit, Deckenlampe_Hobbyraum_Helligkeit)
{
channel ="deconz:colortemperaturelight:raspi4:Deckenlampe_Hobbyraum_Buecherregal:brightness",
homekit="Lighting.Brightness"
}
Number Deckenlampe_Hobbyraum_Buecherregal_Farbtemperatur
"Farbtemperatur Deckenlampe Hobbyraum BĂŒcherregal [%d]"
(Deckenlampe_Hobbyraum_Buecherregal_Homekit, Deckenlampe_Hobbyraum_Farbtemperatur)
{
channel ="deconz:colortemperaturelight:raspi4:Deckenlampe_Hobbyraum_Buecherregal:color_temperature" [ profile="ruby:mired_to_kelvin" ],
homekit="Lighting.ColorTemperature" [minValue=250, maxValue=454],
unit="mired"
}
// Deckenlampe Hobbyraum Mitte
Group Deckenlampe_Hobbyraum_Mitte_Homekit
"Deckenlampe Hobbyraum Mitte Homekit"
{
homekit="Lighting"
}
Switch Deckenlampe_Hobbyraum_Mitte_Einschaltstatus
"Einschaltstatus Deckenlampe Hobbyraum Mitte [MAP(de.map):%s]"
(Deckenlampe_Hobbyraum_Mitte_Homekit, Deckenlampe_Hobbyraum_Einschaltstatus)
{
homekit="Lighting.OnState"
}
Dimmer Deckenlampe_Hobbyraum_Mitte_Helligkeit
"Helligkeit Deckenlampe Hobbyraum Mitte [%d]"
(Deckenlampe_Hobbyraum_Mitte_Homekit, Deckenlampe_Hobbyraum_Helligkeit)
{
channel ="deconz:colortemperaturelight:raspi4:Deckenlampe_Hobbyraum_Mitte:brightness",
homekit="Lighting.Brightness"
}
Number Deckenlampe_Hobbyraum_Mitte_Farbtemperatur
"Farbtemperatur Deckenlampe Hobbyraum Mitte [%d]"
(Deckenlampe_Hobbyraum_Mitte_Homekit, Deckenlampe_Hobbyraum_Farbtemperatur)
{
channel ="deconz:colortemperaturelight:raspi4:Deckenlampe_Hobbyraum_Mitte:color_temperature" [ profile="ruby:mired_to_kelvin" ],
homekit="Lighting.ColorTemperature" [minValue=250, maxValue=454],
unit="mired"
}
// Deckenlampe Hobbyraum Schreibtisch
Group Deckenlampe_Hobbyraum_Schreibtisch_Homekit
"Deckenlampe Hobbyraum Schreibtisch Homekit"
{
homekit="Lighting"
}
Switch Deckenlampe_Hobbyraum_Schreibtisch_Einschaltstatus
"Einschaltstatus Deckenlampe Hobbyraum Schreibtisch [MAP(de.map):%s]"
(Deckenlampe_Hobbyraum_Schreibtisch_Homekit, Deckenlampe_Hobbyraum_Einschaltstatus)
{
homekit="Lighting.OnState"
}
Dimmer Deckenlampe_Hobbyraum_Schreibtisch_Helligkeit
"Helligkeit Deckenlampe Hobbyraum Schreibtisch [%d]"
(Deckenlampe_Hobbyraum_Schreibtisch_Homekit, Deckenlampe_Hobbyraum_Helligkeit)
{
channel ="deconz:colortemperaturelight:raspi4:Deckenlampe_Hobbyraum_Schreibtisch:brightness",
homekit="Lighting.Brightness"
}
Number Deckenlampe_Hobbyraum_Schreibtisch_Farbtemperatur
"Farbtemperatur Deckenlampe Hobbyraum Schreibtisch [%d]"
(Deckenlampe_Hobbyraum_Schreibtisch_Homekit, Deckenlampe_Hobbyraum_Farbtemperatur)
{
channel ="deconz:colortemperaturelight:raspi4:Deckenlampe_Hobbyraum_Schreibtisch:color_temperature" [ profile="ruby:mired_to_kelvin" ],
homekit="Lighting.ColorTemperature" [minValue=250, maxValue=454],
unit="mired"
}
// *** Fernbedienungen ***
Group:Number Fernbedienungen
"Styrbar Fernbedienungen"
// Fernbedienung Hobbyraum
Number Fernbedienung_Hobbyraum
"GedrĂŒckte Taste an Fernbedienung Keller [%d]"
(Fernbedienungen, Deckenlampen_Hobbyraum)
{ channel="deconz:switch:raspi4:Fernbedienung_Hobbyraum:button" }
My slightly adapted rule. Adapted because I receive numbers as commands from the remote:
module ButtonAction
ACTIONS = {
1002 => 'on',
2002 => 'off',
1001 => 'brightness_move_up',
2001 => 'brightness_move_down',
1003 => 'brightness_stop',
2003 => 'brightness_stop',
3002 => 'arrow_left_click',
3001 => 'arrow_left_hold',
3003 => 'arrow_left_release',
4002 => 'arrow_right_click',
4001 => 'arrow_right_hold',
4003 => 'arrow_right_release'
}.freeze
def self.action_name(action_code)
ACTIONS[action_code]
end
end
COLORS = {
cold: 250,
middle: 352,
warm: 454
}.freeze
def blink(dimmer)
power = dimmer.points(Semantics::Level).first
power.off
ensure
after(350.ms) do
power.on
end
end
@colors = Hash.new { |hash, key| hash[key] = COLORS.values }
def adjust(dimmer, delta)
return timers[dimmer]&.cancel if delta.zero?
dimmer.points(Semantics::Level).first&.ensure.on
after(0.ms, id: dimmer) do |timer|
next blink(dimmer) if (dimmer == '100 %' && delta.positive?) || (dimmer <= '1 %' && delta.negative?)
dimmer << (dimmer.to_i + delta).clamp(1, 100)
timer.reschedule 100.ms
end
end
rule 'Ikea Dimmer Handler' do
updated Fernbedienungen.members
triggered do |action|
light = action.equipment
next unless light
dimmer = light.points(Semantics::Level).first
switch = light.points(Semantics::Level).first
ct = light.points(Semantics::ColorTemperature).first
action_name = ButtonAction.action_name(action.state.to_i) # Get the action name
logger.info("Ikea Dimmer Handler - button pressed: #{action_name}")
case action_name
when 'on' then switch.ensure.on
when 'off' then switch.ensure.off
when 'brightness_move_up' then adjust(dimmer, 5)
when 'brightness_move_down' then adjust(dimmer, -5)
when 'brightness_stop' then adjust(dimmer, 0) # Update to adjust(dimmer, 0) or adjust(ct, 0) based on your needs
when 'arrow_left_click' then ct << @colors[dimmer].rotate!.first
when 'arrow_right_click' then ct << @colors[dimmer].rotate!(-1).first
when 'arrow_left_hold' then adjust(ct, -10)
when 'arrow_right_hold' then adjust(ct, 10)
when 'arrow_right_release', 'arrow_left_release' then adjust(ct, 0)
end
end
end
So clicking left/right/up/down works as expected. All three lights are synchronously handled.
But this is what the logs look like when holding down buttons:
2023-08-24 23:05:53.382 [INFO ] [on.jrubyscripting.rule.Lichter.rb:61] - Ikea Dimmer Handler - button pressed: arrow_right_hold
2023-08-24 23:05:53.501 [WARN ] [ore.internal.scheduler.SchedulerImpl] - Scheduled job '<unknown>' failed and stopped
org.jruby.exceptions.NameError: (NameError) undefined method `<=' for class `Kernel'
at org.jruby.RubyModule.instance_method(org/jruby/RubyModule.java:3005) ~[?:?]
at uri_3a_classloader_3a_.META_minus_INF.jruby_dot_home.lib.ruby.stdlib.delegate.method_missing(uri:classloader:/META-INF/jruby.home/lib/ruby/stdlib/delegate.rb:85) ~[?:?]
at RUBY.adjust(/openhab/conf/automation/jsr223/Lichter.rb:54) ~[?:?]
at RUBY.execute(/openhab/conf/automation/ruby/.gem/9.3.10.0/gems/openhab-scripting-5.5.0/lib/openhab/core/timer.rb:133) ~[?:?]
at openhab.conf.automation.ruby.$_dot_gem.$9_dot_3_dot_10_dot_0.gems.openhab_minus_scripting_minus_5_dot_5_dot_0.lib.openhab.dsl.thread_local.thread_local(/openhab/conf/automation/ruby/.gem/9.3.10.0/gems/openhab-scripting-5.5.0/lib/openhab/dsl/thread_local.rb:44) ~[?:?]
at RUBY.execute(/openhab/conf/automation/ruby/.gem/9.3.10.0/gems/openhab-scripting-5.5.0/lib/openhab/core/timer.rb:133) ~[?:?]
at RUBY.initialize(/openhab/conf/automation/ruby/.gem/9.3.10.0/gems/openhab-scripting-5.5.0/lib/openhab/core/timer.rb:52) ~[?:?]
2023-08-24 23:05:53.846 [INFO ] [on.jrubyscripting.rule.Lichter.rb:61] - Ikea Dimmer Handler - button pressed: arrow_right_release
2023-08-24 23:05:53.863 [ERROR] [on.jrubyscripting.rule.Lichter.rb:61] - undefined method `[]' for #<OpenHAB::DSL::TimerManager:0xa340193> (NoMethodError)
/openhab/conf/automation/jsr223/Lichter.rb:49:in `adjust'
/openhab/conf/automation/jsr223/Lichter.rb:85:in `block in <main>'
2023-08-24 23:05:53.895 [INFO ] [on.jrubyscripting.rule.Lichter.rb:61] - Ikea Dimmer Handler - button pressed: arrow_right_hold
2023-08-24 23:05:54.021 [WARN ] [ore.internal.scheduler.SchedulerImpl] - Scheduled job '<unknown>' failed and stopped
org.jruby.exceptions.NameError: (NameError) undefined method `<=' for class `Kernel'
at org.jruby.RubyModule.instance_method(org/jruby/RubyModule.java:3005) ~[?:?]
at uri_3a_classloader_3a_.META_minus_INF.jruby_dot_home.lib.ruby.stdlib.delegate.method_missing(uri:classloader:/META-INF/jruby.home/lib/ruby/stdlib/delegate.rb:85) ~[?:?]
at RUBY.adjust(/openhab/conf/automation/jsr223/Lichter.rb:54) ~[?:?]
at RUBY.execute(/openhab/conf/automation/ruby/.gem/9.3.10.0/gems/openhab-scripting-5.5.0/lib/openhab/core/timer.rb:133) ~[?:?]
at openhab.conf.automation.ruby.$_dot_gem.$9_dot_3_dot_10_dot_0.gems.openhab_minus_scripting_minus_5_dot_5_dot_0.lib.openhab.dsl.thread_local.thread_local(/openhab/conf/automation/ruby/.gem/9.3.10.0/gems/openhab-scripting-5.5.0/lib/openhab/dsl/thread_local.rb:44) ~[?:?]
at RUBY.execute(/openhab/conf/automation/ruby/.gem/9.3.10.0/gems/openhab-scripting-5.5.0/lib/openhab/core/timer.rb:133) ~[?:?]
at RUBY.initialize(/openhab/conf/automation/ruby/.gem/9.3.10.0/gems/openhab-scripting-5.5.0/lib/openhab/core/timer.rb:52) ~[?:?]
2023-08-24 23:05:59.528 [INFO ] [on.jrubyscripting.rule.Lichter.rb:61] - Ikea Dimmer Handler - button pressed: arrow_left_hold
2023-08-24 23:05:59.648 [WARN ] [ore.internal.scheduler.SchedulerImpl] - Scheduled job '<unknown>' failed and stopped
org.jruby.exceptions.NameError: (NameError) undefined method `<=' for class `Kernel'
at org.jruby.RubyModule.instance_method(org/jruby/RubyModule.java:3005) ~[?:?]
at uri_3a_classloader_3a_.META_minus_INF.jruby_dot_home.lib.ruby.stdlib.delegate.method_missing(uri:classloader:/META-INF/jruby.home/lib/ruby/stdlib/delegate.rb:85) ~[?:?]
at RUBY.adjust(/openhab/conf/automation/jsr223/Lichter.rb:54) ~[?:?]
at RUBY.execute(/openhab/conf/automation/ruby/.gem/9.3.10.0/gems/openhab-scripting-5.5.0/lib/openhab/core/timer.rb:133) ~[?:?]
at openhab.conf.automation.ruby.$_dot_gem.$9_dot_3_dot_10_dot_0.gems.openhab_minus_scripting_minus_5_dot_5_dot_0.lib.openhab.dsl.thread_local.thread_local(/openhab/conf/automation/ruby/.gem/9.3.10.0/gems/openhab-scripting-5.5.0/lib/openhab/dsl/thread_local.rb:44) ~[?:?]
at RUBY.execute(/openhab/conf/automation/ruby/.gem/9.3.10.0/gems/openhab-scripting-5.5.0/lib/openhab/core/timer.rb:133) ~[?:?]
at RUBY.initialize(/openhab/conf/automation/ruby/.gem/9.3.10.0/gems/openhab-scripting-5.5.0/lib/openhab/core/timer.rb:52) ~[?:?]
2023-08-24 23:06:00.714 [INFO ] [on.jrubyscripting.rule.Lichter.rb:61] - Ikea Dimmer Handler - button pressed: arrow_left_release
2023-08-24 23:06:00.728 [ERROR] [on.jrubyscripting.rule.Lichter.rb:61] - undefined method `[]' for #<OpenHAB::DSL::TimerManager:0xa340193> (NoMethodError)
/openhab/conf/automation/jsr223/Lichter.rb:49:in `adjust'
/openhab/conf/automation/jsr223/Lichter.rb:75:in `block in <main>'
2023-08-24 23:06:09.368 [INFO ] [on.jrubyscripting.rule.Lichter.rb:61] - Ikea Dimmer Handler - button pressed: brightness_move_down
2023-08-24 23:06:09.387 [ERROR] [on.jrubyscripting.rule.Lichter.rb:61] - undefined method `on' for nil:NilClass (NoMethodError)
/openhab/conf/automation/jsr223/Lichter.rb:51:in `adjust'
/openhab/conf/automation/jsr223/Lichter.rb:79:in `block in <main>'
2023-08-24 23:06:13.143 [INFO ] [on.jrubyscripting.rule.Lichter.rb:61] - Ikea Dimmer Handler - button pressed: brightness_stop
2023-08-24 23:06:13.157 [ERROR] [on.jrubyscripting.rule.Lichter.rb:61] - undefined method `[]' for #<OpenHAB::DSL::TimerManager:0xa340193> (NoMethodError)
/openhab/conf/automation/jsr223/Lichter.rb:49:in `adjust'
/openhab/conf/automation/jsr223/Lichter.rb:80:in `block in <main>'
2023-08-24 23:06:17.036 [INFO ] [on.jrubyscripting.rule.Lichter.rb:61] - Ikea Dimmer Handler - button pressed: brightness_move_up
2023-08-24 23:06:17.052 [ERROR] [on.jrubyscripting.rule.Lichter.rb:61] - undefined method `on' for nil:NilClass (NoMethodError)
/openhab/conf/automation/jsr223/Lichter.rb:51:in `adjust'
/openhab/conf/automation/jsr223/Lichter.rb:78:in `block in <main>'
2023-08-24 23:06:19.598 [INFO ] [on.jrubyscripting.rule.Lichter.rb:61] - Ikea Dimmer Handler - button pressed: brightness_stop
2023-08-24 23:06:19.647 [ERROR] [on.jrubyscripting.rule.Lichter.rb:61] - undefined method `[]' for #<OpenHAB::DSL::TimerManager:0xa340193> (NoMethodError)
/openhab/conf/automation/jsr223/Lichter.rb:49:in `adjust'
/openhab/conf/automation/jsr223/Lichter.rb:80:in `block in <main>'
Any idea what the issue might be here? I am using OH 3.4.5 with openhab-scripting=~>5.0
.
Bonus question:
You can see that homekit requires an OnState
property which must be a Switch
item. Otherwise homekit refuses to work. This item always must be synchronized with the Dimmer
item.
If the Dimmer
was changed by the user above 0%, then the Switch
item must be switched on and vice versa. So it is possible that both items can be changed by a user or by the system.
Is there a convenient way how all equipments of that type can be synchronized?
It is the same for the item
Group:Switch Deckenlampe_Hobbyraum_Einschaltstatus
(Deckenlampen_Hobbyraum)
["Control", "Light"]
Currently, if I switch it off, nothing happens. I need to sync it with the Dimmer
item controlling the brightness.