Switch Problem

Hi there!

Im new to the whole openhab thing and dont have much experience in programming too.

Despite this, im trying to build my own Smarthome interface to controll my stuff via wall panel.

I created several items and implemented them to a habpanel dashboard. Everything works fine, when i do it in the dashboard.

But i have a Problem which i cannot solve on my own.

How do i manage, that some switches recognize when i e.g. Turn lights on/off manually to via Hue App?

In the dashboard i want a button, that turns on light in a specific state (Color, brightness) on the First Input.
And turns off on the second Input.
This works with the Button Widget given in openhab.
But when i changed color with the hue App, it recognized it as „off“ because the State (30,30,30) is no longer active and so it turned the button in inaktive state although the light is still on.
Ive tried to create a Switch item, that turns on/off when Click on the Button and two rules that turns light on(30,30,30) and off when the Virtual Switch item is on/off. Then i linked the Button in the dashboard with that Switch. Works fine… But….
The Switch doesnt recognize the change, when i Turn off/on physically or via hue App.

I want the Button to be active when lights are ON no matter what Color or brightness they have and no matter if they are turned on with dashboard Button or hue App or physically.
The Same goes for the OFF state.

I tried several Rules, but i think im out of Ideas.

Can someone plz help?

It sounds like …

You’ve made a “dummy” Switch Item, that is not linked to anything.
You can send it commands from the GUI, and have created rules to act on those commands to control other devices.

Unsurprisingly, because it is not linked to anything, changes in any other device or Item are not reflected in the Switch.
I think you need another rule that listens for changes in the target Item(s) and updates the Switch Item state?

Thank you very much. I dont knew you can link a switch to an item.
I did that and created two rules, which turns in the Lamp with specific settings (color, brightness) When switch is on and turns ist off when switch is off. Then i Linked the Button with the switch.
Works Fine. Even if i change color or turn off/on manually.
The only Problem now is, that the switch and so the Button are very delayed. So their status is changing only after a few seconds and Not immediatly. Is there a possibility to make this faster?

I’m afraid I’ve completely lost track of what you are taking about. I though that was what you described in the first place.
I think we’ll need some details about your UI widget, the Item it interacts with, the rules that you are using to make that Item interact in turn with whatever Items represent your real devices, and what those Items are.
You might understand what is happening better if you look into your events.log.

Im sorry. Maybe the last hours of trying to get it work, made me a little bit gaga :joy:

I‘ll try to explain.

I have several Light Bulbs from Phillips hue. Theyre connected with a hue Bridge.
I have the Hue App to Control them.(or HomeKit)
Now ive set up an raspberry pi 4 with openhab.
All devices are in the Same Network.
In Future I want to have several Wall mounted panels (also raspberries but zeroes with touchpanel) I want them all to show my openhab dashboard to control the several Lights, radiators and so on.
So long for my plans.

On my Dashboard (HABPanel) im using the Standard Button Widget.

The Button should do this:
When I press it, it turns several lamps on in a specific State. Like a scene in the hue App. (E.g. Bulb1=red, bulb2=Green, bulb3=Blue. And all in a specific brightness)
The Button should Show, that the bulbs, or at least one of them is „ON“ no matter in wich color or brightness. It should be an indicator to See, if there is at least one bulb on.
At the second Click on the Button, ALL bulbs in that room should turn off. The button shows its inactive and ill see, everything is OFF.
The Button should Show active/inactive too, when I manually turn on/off the lights via hue App or physically.

Long story Short. I want that Button to show if at least one Light in that room is on or if theyre all off. And with clicking on it, it should switch several bulbs on and all off.

I managed this Till now with a switch in openhab.
The dashboard Button turns on/off that switch.
One Rule says that if the switch is ON bulb1 &2 &3 will turn on in red,Blue,Green.
The other rule says that all bulbs turn Off, if the switch is OFF.
The switch itself is linked to the channels of the bulbs.
This turns it on/off, when at least is one bulb is on, Even, if i turn the Bulb on/off via hue app(this is, what my former Problem was and you told ne to do so. It works. Thanks :D)

My Problem now is, that the switch is very delayed, when I Control the lamps via Hue app.(It turns off After 6 seconds and on After 3-4 seconds) The Button in the dashboard reacts delayed too with Activ/inactive, because it only changes its Status, when the switch toogles.
My question was, if it is possible to shorten this time.

The other Problem is, that the switch turns off, when i turn of only one of the bulbs via App, even if the other two are still on.
It turns on too, when I turn only one bulb on via App, but that doesnt does any Harm, because it should be on, if at least one bulb is on.
How could i manage, that the switch stays ON, even if one bulb is turned off manually?

Im sorry for my Bad english. Its Not good enough to explain such complex things, but i hope I was able to tell you, what you have to know to help me :sweat_smile:

Everything in openHAB revolves around Items. Your GUI interfaces with Items, your Hue devices interface with Items, your rules operate on Items. Please try to describe what you are doing in terms of your Items, when you say Bulb or Switch we don’t know if you mean an Item, a real device, or something on your UI.

Have a look in your events.log, and copy paste for us the relevant sequence of events. They’ve got timestamps, so your delay should show there. You’ll need to explain to us what each of the named Items represent, and what you expected to happen.

If your rules are not doing what you expect, you will need to show those as well.

2021-12-16 00:54:36.046 [INFO ] [openhab.event.ItemCommandEvent ] - Item ‘Switch_Lichtszene’ received command ON
2021-12-16 00:54:36.048 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item ‘Switch_Lichtszene’ predicted to become ON
2021-12-16 00:54:36.057 [INFO ] [openhab.event.ItemCommandEvent ] - Item ‘Nachttischlampe_Farbe’ received command 31,100,100
2021-12-16 00:54:36.061 [INFO ] [openhab.event.ItemCommandEvent ] - Item ‘Schlafzimmerlampe_Farbe’ received command 44,73,54
2021-12-16 00:54:36.062 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item ‘Switch_Lichtszene’ changed from OFF to ON
2021-12-16 00:54:36.062 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item ‘Nachttischlampe_Farbe’ predicted to become 31,100,100
2021-12-16 00:54:36.064 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item ‘Schlafzimmerlampe_Farbe’ predicted to become 44,73,54
2021-12-16 00:54:36.066 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item ‘Nachttischlampe_Farbe’ changed from 31,100,0 to 31,100,100
2021-12-16 00:54:36.067 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item ‘Schlafzimmerlampe_Farbe’ changed from 43,72,0 to 44,73,54
2021-12-16 00:54:40.190 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item ‘Schlafzimmerlampe_Farbe’ changed from 44,73,54 to 43,72,54
2021-12-16 00:54:40.195 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item ‘Nachttischlampe_Farbe’ changed from 31,100,100 to 31,100,88
2021-12-16 00:54:40.197 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item ‘Switch_Nachttischlampe’ changed from OFF to ON
2021-12-16 00:54:40.871 [INFO ] [openhab.event.ItemCommandEvent ] - Item ‘Switch_Lichtszene’ received command OFF
2021-12-16 00:54:40.872 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item ‘Switch_Lichtszene’ predicted to become OFF
2021-12-16 00:54:40.880 [INFO ] [openhab.event.ItemCommandEvent ] - Item ‘Nachttischlampe_Farbe’ received command OFF
2021-12-16 00:54:40.882 [INFO ] [openhab.event.ItemCommandEvent ] - Item ‘Schlafzimmerlampe_Farbe’ received command OFF
2021-12-16 00:54:40.883 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item ‘Switch_Lichtszene’ changed from ON to OFF
2021-12-16 00:54:40.884 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item ‘Nachttischlampe_Farbe’ predicted to become OFF
2021-12-16 00:54:40.886 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item ‘Schlafzimmerlampe_Farbe’ predicted to become OFF
2021-12-16 00:54:40.887 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item ‘Nachttischlampe_Farbe’ changed from 31,100,88 to 31,100,0
2021-12-16 00:54:40.888 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item ‘Schlafzimmerlampe_Farbe’ changed from 43,72,54 to 43,72,0
2021-12-16 00:54:48.283 [INFO ] [openhab.event.ItemCommandEvent ] - Item ‘Switch_Lichtszene’ received command ON
2021-12-16 00:54:48.287 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item ‘Switch_Lichtszene’ predicted to become ON
2021-12-16 00:54:48.291 [INFO ] [openhab.event.ItemCommandEvent ] - Item ‘Nachttischlampe_Farbe’ received command 31,100,100
2021-12-16 00:54:48.295 [INFO ] [openhab.event.ItemCommandEvent ] - Item ‘Schlafzimmerlampe_Farbe’ received command 44,73,54
2021-12-16 00:54:48.296 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item ‘Switch_Lichtszene’ changed from OFF to ON
2021-12-16 00:54:48.298 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item ‘Nachttischlampe_Farbe’ predicted to become 31,100,100
2021-12-16 00:54:48.302 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item ‘Schlafzimmerlampe_Farbe’ predicted to become 44,73,54
2021-12-16 00:54:48.306 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item ‘Nachttischlampe_Farbe’ changed from 31,100,0 to 31,100,100
2021-12-16 00:54:48.307 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item ‘Schlafzimmerlampe_Farbe’ changed from 43,72,0 to 44,73,54
2021-12-16 00:54:50.237 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item ‘Schlafzimmerlampe_Farbe’ changed from 44,73,54 to 43,72,54
2021-12-16 00:55:00.285 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item ‘Nachttischlampe_Farbe’ changed from 31,100,100 to 31,100,0
2021-12-16 00:55:00.289 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item ‘Switch_Nachttischlampe’ changed from ON to OFF
2021-12-16 00:55:00.290 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item ‘Switch_Lichtszene’ changed from ON to OFF

That is my logfile.

Switch_lichtszene is an item i build Which turns on/off, when i press the Button on the dashboard.

Nachttischlampe_Farbe is an item which is a channel of my nachttischlampe thing (a hue bulb)

The Same goes for schlafzimmerlampe_farbe.

When the dashboard Button is pushed, the switch item (switch_lichtszene) turns on.

triggers:

  • id: “1”
    configuration:
    itemName: Switch_Lichtszene
    command: OFF
    type: core.ItemCommandTrigger
    conditions: []
    actions:
  • inputs: {}
    id: “2”
    configuration:
    itemName: Nachttischlampe_Farbe
    command: OFF
    type: core.ItemCommandAction
  • inputs: {}
    id: “3”
    configuration:
    itemName: Schlafzimmerlampe_Farbe
    command: OFF
    type: core.ItemCommandAction

This rule does, that both items(nachttischlampe_farbe and schlafzimmerlampe_farbe) turn off, when the switch (switch_lichtszene) is turned off

triggers:

  • id: “1”
    configuration:
    itemName: Switch_Lichtszene
    command: ON
    type: core.ItemCommandTrigger
    conditions: []
    actions:
  • inputs: {}
    id: “2”
    configuration:
    itemName: Nachttischlampe_Farbe
    command: 31,100,100
    type: core.ItemCommandAction
  • inputs: {}
    id: “3”
    configuration:
    itemName: Schlafzimmerlampe_Farbe
    command: 44,73,54
    type: core.ItemCommandAction

This rule sets both items(nachttischlampe_farbe and schlafzimmerlampe_farbe) to a specific value which results an colors and brightness.

At 00.55.00.289 (second Last Entry) you See, that I turned off the Lamp (which is also an item in Openhab, Nachttischlampe_color) manually via Mobile App.
Then(Last entry) it turns off my switch (switch _lichtszene ) automatically although the Lamp (schlafzimmerlampe_color item) is still on

But I want the Switch (Switch_lichtszene) to Star On, if there is at least on Lamp on

Why would it do that, have you linked it to something?

It sounds like you have. You don’t want that, because if any device sends an update “off” it will turn the dummy Switch Item OFF. That’s how it is supposed to work if you link multiple channels to one Item.
So remove those links.

Now you have to find another way to get the devices to update the dummy Switch Item state.
Usually that is managed with Groups. But Groups, when commanded, send the same command to all member Items - you cannot use that on your UI because you want to send different colours to each device.
So keep the dummy Switch Item for use on your UI.

But we can cheat and use a Group to work out the on/off state of your Hue Items.
Create a Group type Item. Make it a Switch sub-type - if you use the GUI, it misleading calls that “member types” - it isn’t really, this is the Group type.
Give the Group an aggregation function of “ON if any members ON”
Now make each Hue Item a member of this new Group - yes, you can make Color Items members of a Switch-subtype Group.
The Group will automatically update to ON/OFF from changes of your Hue Items.
You can check if that works in your events.log

The you need a simple rule to make your dummy Switch Item follow the Group.
Trigger from Group state update.
Send the new state to your dummy Switch.

Thank you very much. Because of this group/switch Item and some rules(I have Four now) it works!!!

Now the only issue is the Delay. Here is my log Where you can See what Happens, when I Turn off/on both lamps with the Hue App.
It does what it should do, but sometimes the item-switches and so the Button in the dashboard react only After 6-7 seconds. Is there a way to change the time openhab checks for the status of the devices and update them quicker?

12-16 04:22:38.738 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item ‘Nachttischlampe_Farbe’ changed from 341,79,0 to 341,79,100
2021-12-16 04:22:38.740 [INFO ] [hab.event.GroupItemStateChangedEvent] - Item ‘Schlafzimmer_Gruppe_Switch’ changed from OFF to ON through Nachttischlampe_Farbe
2021-12-16 04:22:38.744 [INFO ] [openhab.event.ItemCommandEvent ] - Item ‘Lichtszene_Schlafzimmer_Switch’ received command ON
2021-12-16 04:22:38.746 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item ‘Lichtszene_Schlafzimmer_Switch’ changed from OFF to ON
2021-12-16 04:22:48.785 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item ‘Nachttischlampe_Farbe’ changed from 341,79,100 to 341,79,0
2021-12-16 04:22:48.787 [INFO ] [hab.event.GroupItemStateChangedEvent] - Item ‘Schlafzimmer_Gruppe_Switch’ changed from ON to OFF through Nachttischlampe_Farbe
2021-12-16 04:22:48.791 [INFO ] [openhab.event.ItemCommandEvent ] - Item ‘Lichtszene_Schlafzimmer_Switch’ received command OFF
2021-12-16 04:22:48.792 [INFO ] [openhab.event.ItemCommandEvent ] - Item ‘Schlafzimmer_Gruppe_Switch’ received command OFF
2021-12-16 04:22:48.793 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item ‘Lichtszene_Schlafzimmer_Switch’ changed from ON to OFF
2021-12-16 04:22:48.795 [INFO ] [openhab.event.ItemCommandEvent ] - Item ‘Nachttischlampe_Farbe’ received command OFF
2021-12-16 04:22:48.797 [INFO ] [openhab.event.ItemCommandEvent ] - Item ‘Schlafzimmerlampe_Farbe’ received command OFF
2021-12-16 04:22:48.798 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item ‘Nachttischlampe_Farbe’ predicted to become OFF
2021-12-16 04:22:48.800 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item ‘Schlafzimmerlampe_Farbe’ predicted to become OFF

But this is the smallest Problem. Im glad, the Thing does, what it should do and Thank you for your patience and advice :smiley:

I don’t think it works like that. openHAB waits for the Hue Bridge to tell it what is happening.