Aqara buttons - not declarable as item [solved]

Hi there

I am setting up my environment with several xiaomi or aqara items. Everything is working quite well but the switches. When I am integrating the switches I am able declaring battery and low battery as things. But I am not able integrating the switch as a thing.

Yes, I have been searching plenty of documentation - but I can’t find anything in concrete.

Here my concrete question:

  • So how do I integrate a button event? The button is always grey, can’t turn it into blue to convert it into an Item. So I would be very pleased if you could give me a short description how to.

I used the current version of openhabian 2.2

Thank you in advance

If it is greyed out it is not supported by the binding.

I don’t have a wireless switch, but according to the docs you have to use trigger channels for the buttons:

https://docs.openhab.org/addons/bindings/mihome/readme.html

rule "Xiaomi Switch"
when
    Channel "mihome:sensor_switch:<ID>:button" triggered
then
    var actionName = receivedEvent.getEvent()
    switch(actionName) {
        case "SHORT_PRESSED": {
            <ACTION>
        }
        case "DOUBLE_PRESSED": {
            <ACTION>
        }
        case "LONG_PRESSED": {
            <ACTION>
        }
        case "LONG_RELEASED": {
            <ACTION>
        }
    }
end
1 Like

I can confirm, that’s the way to use MiHome switches. works with my Aqara switches fine.
(only thing is, I’m never sure, if I short pressed or long pressed … that’s a bit tricky to find out - if you need an differentiator)

1 Like

Ok, thanks. I hope it to be supported soon. In the meantime I will try to start coding and testing it.

Thank you very much.

The intended use case is to use the channel triggers …

I honestly don’t see a real need for trigger-items or event-items also…

Well that is the reason why I am posting this within the newbie channel.

I studied many parts of the documentation. What I am missing are common and simple use cases. E.g. illuminating a light by a push of the button. Well it is quite often I saw the channel trigger word…but it is not trivial for a newbie bringing it into context fulfilling this simple use case.

So what do you suggest as a use-case-doc as described above?

Thank you in advance again :slight_smile:

PS: Playing the piano is a trivial thing - if you’re able to :wink:

You would put your action inside the case statements. You may need to do some checking to identify the current state to send the appropriate command as in the Double Click example below.
You can do/control anything you would otherwise in a rule.

I have a button for my wife and I. Single click turns controls our respective lamp, double click controls the other, and long press controls the bedroom ceiling light.

rule "Xiaomi Switch"
when
    Channel "mihome:sensor_switch:<ID>:button" triggered
then
    var actionName = receivedEvent.getEvent()
    switch(actionName) {
        case "SHORT_PRESSED": {
            myLight.sendCommand(ON)
        }
        case "DOUBLE_PRESSED": {
            if (myOtherLight.state == OFF) myOtherLight.sendCommand(ON)
            else myOtherLight.sendCommand(OFF)
        }
        case "LONG_PRESSED": {
            myFan.sendCommand(ON)
        }
        case "LONG_RELEASED": {
            <ACTION>
        }
    }
end

Oh, sorry, if our remarks intended otherwise. We respect everybody here in the forum - especially newbies!
We “old ones” just talked about “trigger/event”-items. Let’s say your sensor had indeed an item indicating presses. They would turn “ON” for an instant and would then immediately turn “OFF” again. And that’s where handling them gets a) complicated and b) too complicated for newbies to understand.
That being said - events are the best way to use such things as Buttons.

and yes, cody wrote the perfect example for you, I hope!

1 Like

Thank you very much. Now I got it and I got a little closer to openhab’s philosophy.

Just one last question: How do I use boolean operators. In my case if want to see within which range the current state is. To give an example:

		if (YeelightColorLEDStripe_Brightness.state > 0 AND YeelightColorLEDStripe_Brightness.state < 34)
		YeelightColorLEDStripe_Brightness.sendCommand(66)	
		else
			if (YeelightColorLEDStripe_Brightness.state > 33 AND YeelightColorLEDStripe_Brightness.state < 67)
			YeelightColorLEDStripe_Brightness.sendCommand(100)

Where do I find a good doc describing this? Cause it does not work… Which language or accent is it openhab is using?

Thank you so far.

openHAB rules use XTEND: https://eclipse.org/xtend/documentation/
The documentation is far from perfect, so…
but replace AND with && and it will work:

tipp one: use an decent Editor - it’ll give you hints on the Syntax: https://docs.openhab.org/configuration/editors.html
and one more tipp: use curly brackets, if you have more than one action or if the Action is in the next line (no python style! :wink: ).

if (YeelightColorLEDStripe_Brightness.state > 0 && YeelightColorLEDStripe_Brightness.state < 34) {
	YeelightColorLEDStripe_Brightness.sendCommand(66)
} else if (YeelightColorLEDStripe_Brightness.state > 33 && YeelightColorLEDStripe_Brightness.state < 67) {
	YeelightColorLEDStripe_Brightness.sendCommand(100)
}

Great! And thanks for your tipps. That is very helpful - and very kind :slight_smile:

I’ll take the blame on that one. I should have used brackets in my example.
And I wonder why I can’t even keep to a consistent format for my Item naming. :stuck_out_tongue_winking_eye: