[SOLVED] Item value reverts to original straight away

Hi Team,

I’ve got a wired issue with Mi Smart home binding (or that might be rules, or my fingers…).
Whenever I change the value from the rule it comes back to original value straight away.
My simple rule:

rule "Kids Room - Double switch - ch1 - long"
when
    Channel "mihome:86sw2:158d0234a9c70:ch1" triggered LONG_PRESSED
then
    if ( Mi_LED_Strip_1_Brightness.state < 50 ) {
		Mi_LED_Strip_1_Brightness.sendCommand(100) }
	else if ( Mi_LED_Strip_1_Brightness.state > 50 ) {
		Mi_LED_Strip_1_Brightness.sendCommand(1) }
end

And this is what is happening in the logs:

2019-03-21 13:07:56.934 [vent.ChannelTriggeredEvent] - mihome:86sw2:158d0234a9c70:ch1 triggered LONG_PRESSED
2019-03-21 13:07:56.940 [ome.event.ItemCommandEvent] - Item 'Mi_LED_Strip_1_Brightness' received command 100
2019-03-21 13:07:56.944 [nt.ItemStatePredictedEvent] - Mi_LED_Strip_1_Brightness predicted to become 100
2019-03-21 13:07:56.963 [vent.ItemStateChangedEvent] - Mi_LED_Strip_1_Brightness changed from 1 to 100
2019-03-21 13:07:56.966 [ome.event.ItemCommandEvent] - Item 'Mi_LED_Strip_1_Brightness' received command 1
2019-03-21 13:07:56.972 [nt.ItemStatePredictedEvent] - Mi_LED_Strip_1_Brightness predicted to become 1
2019-03-21 13:07:56.975 [vent.ItemStateChangedEvent] - Mi_LED_Strip_1_Brightness changed from 100 to 1

Even the simpler rule gets the same result

rule "Kids Room - Double switch - ch1 - long"
when
    Channel "mihome:86sw2:158d0002ea9c70:ch1" triggered LONG_PRESSED
then
	Mi_LED_Strip_1_Brightness.sendCommand(100)
end

What am I dong wrong?
Thanks!!

Try:

rule "Kids Room"
when
    Channel 'mihome:86sw2:158d0234a9c70:ch1' triggered LONG_PRESSED
then
    if ( Mi_LED_Strip_1_Brightness.state < 50 ) {
		Mi_LED_Strip_1_Brightness.sendCommand(100) }
	else ( Mi_LED_Strip_1_Brightness.state > 50 ) {
		Mi_LED_Strip_1_Brightness.sendCommand(1) }
end

Nah, still the same.
Even when I try without if, else result is the same unfortunately…

Throw some logInfo on each line so you can see where it is happening (I assume you don’t have any associations that would cause the switch to turn on the light without the rule (try disabling the rule even as a step 1)

Did you use the example or only change the if else? Please, try with the modified rule name and changing the " " to ’ ’ in the when section.

You can even change

else ( Mi_LED_Strip_1_Brightness.state > 50 ) {
		Mi_LED_Strip_1_Brightness.sendCommand(1) }

to

else 
    Mi_LED_Strip_1_Brightness.sendCommand(1) 

As there is no reason to re-evaluate the item state. If it’s not less than 50 (checked with if statement) then it can only be greater than 50.

Thanks for helping!

Tried both, same…

rule "Kids Room"
when
    Channel 'mihome:86sw2:158d0234a9c70:ch2' triggered SHORT_PRESSED
then
    if ( Mi_LED_Strip_1_Brightness.state < 50 ) {
		Mi_LED_Strip_1_Brightness.sendCommand(100) }
	else 
		Mi_LED_Strip_1_Brightness.sendCommand(1)
end

log:

2019-03-21 13:37:23.388 [vent.ChannelTriggeredEvent] - mihome:86sw2:158d0234a9c70:ch2 triggered SHORT_PRESSED
2019-03-21 13:37:23.393 [ome.event.ItemCommandEvent] - Item 'Mi_LED_Strip_1_Brightness' received command 100
2019-03-21 13:37:23.397 [nt.ItemStatePredictedEvent] - Mi_LED_Strip_1_Brightness predicted to become 100
2019-03-21 13:37:23.403 [vent.ItemStateChangedEvent] - Mi_LED_Strip_1_Brightness changed from 1 to 100
2019-03-21 13:37:23.481 [vent.ItemStateChangedEvent] - Mi_LED_Strip_1_Brightness changed from 100 to 1

Try adding as Number like below.

if ( Mi_LED_Strip_1_Brightness.state as Number < 50 ) {

If that doesn’t work please post the item or item state definition.

Error log:

2019-03-21 13:45:14.633 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'mihome.rules' has errors, therefore ignoring it: [105,54]: no viable alternative at input '50'

Item:

Number      Mi_LED_Strip_1_Brightness       "Kids LED Brightness"            (Mi_LED_Strip_1)        {channel="miio:generic:05EC3477:brightness"}

Change the item from Number to Dimmer.

No luck as well…
I’ve removed as Number

Sorry I should have explained where to change the item.:neutral_face:
Change the item (in the items file) like below.

Dimmer      Mi_LED_Strip_1_Brightness       "Kids LED Brightness"            (Mi_LED_Strip_1)        {channel="miio:generic:05EC3477:brightness"}

1 Like

Sorry, I should have told that I’ve changed the item type.
But anyway, this is not working as well

I’ve checked this item is not listed in any other rule

Wish I could give better advise and had more time but at the moment I’m currently running outta both.:roll_eyes:

Hang in there, I’m sure other’s will be able to assist.

Best of luck.

1 Like

The first state change comes from autoupdate, in response to the command.

Then your xioami binding changes state to 1.

Looks like your channel is behaving as a 0/1 switch, not a dimmer?

Binding doc says

miio:generic Generic type for discovered devices. Once the token is available and the device model is determined, this ThingType will automatically change to the appropriate ThingType

I wouldn’t expect to see generic in your channel?
I think you need to read the part about tokens.

I’ve tried uninstalling the binding and installing back.
Deleted the thing and getting it back.
It is still discovered as generic

That seems to be what’s supposed to happen, but you’re missing the part about device model and token. I know nothing about miio. Maybe this device isn’t supported. Have you got the token?

I’ve got the token and can control the item from OH.
If I jus turn it ON and OFF from the rules, that works fine.
The only issue is with changing the brightness.

Beats me.

May we see the events log for these changes? What happens if you use a slider from UI?

Thanks for helping out :wink:

I’ve recorded a short video: https://bit.ly/2TP08qO
Everything else works fine, changing modes, color temperatures, but the brightness slider always goes to 100%

Slider looks weird in your UI. Full width? We’d better see this part of your sitemap.

On the other hand, it does seem to issue only one numeric command, like a slider is supposed to do, and that is what matters for the issue at hand.

I still think it’s the binding that is updating the Item state back to 100% after a command, because it happens in a very short timeframe. That could even be normal behaviour but is then supposed to be followed in a few mS by an update from the real device reflecting its new state. I don’t know.
I suspect a binding debug log is the next step.

Unless you have found a hidden rule that postUpdates the Item?!