[SOLVED]How does a dimmer work?

This is autoupdate feature at work.
Autoupdate listens for commands sent to Items, and predicts what the effect will be on the Item state.
Why? For a quick response - some devices may give a prompt status update back to openHAB, some may be slow, some may never give one, some Items are not bound to any real device.

So -
2019-03-19 22:33:14.495 [ome.event.ItemCommandEvent] - Item ‘DimmerCam’ received command 37
Here’s your command.

2019-03-19 22:33:14.508 [nt.ItemStatePredictedEvent] - DimmerCam predicted to become 37
Here’s autoupdate’s prediction, or guess, at the outcome.

2019-03-19 22:33:14.531 [vent.ItemStateChangedEvent] - DimmerCam changed from UNDEF to 37
Here’s your Item actually getting updated by autoupdate

2019-03-19 22:33:14.543 [vent.ItemStateChangedEvent] - DimmerCam changed from 37 to UNDEF
What’s this then? This has come from the device binding, the real state of the device.
But the binding to your Item is in error so you get the UNDEF.

You can disable autoupdate for your Item, which will stop the guesswork part.

But of course the real problem is that your MQTT setup is not updating your Item properly.

No, you did not :slight_smile: detail

How can i resolve it?

The problem could be anywhere in the communication between your sonoff and openhab.

  1. What info does your sonoff publish and to which mqtt topics?
  2. In what format does it publish the info?
  3. Is your topic channel on openhab configured correctly to receive the info?
  4. Do you need to transform the info to make openhab understand it?

Maybe the problem is on the channel.
I set the Dimmer “DimmerCam” but the field of the state and command in openhab are blank.
This because i want to use the dimner only to determine the time that the rule wait for turn off the switch.
I’m not expect e response from the sonoff
I think this is correct.
Don’t you think that?

If i erase the variable x and i put a number as argument of the command TIMER it works correctly

So, this is just a value to be used for timing?
Why have you made it a Dimmer Item, a Number would be more sensible surely.
If you only want to use the value in a rule why have linked it to MQTT?

That’s right. So i should unlink from the Mqtt broker.
This evening i will try and i hope to resolve.
I continue to use the dimmer only to set a % of opening of the blind

I report the situation:




Now It doesn’t work.

i unlink the dimmer from mqtt.
the DimmerCam is now defined as a number that i use in the rule:

rule "apertura"


when 

Item LivingRoom_Light1 changed to ON

then

 var x = (DimmerCam.state as Number * 0.24)
	
 createTimer(now.plusSeconds(x)) [|
LivingRoom_Light1.sendCommand(OFF)
]
end

and this is the log

2019-03-20 18:52:35.706 [ome.event.ItemCommandEvent] - Item ‘DimmerCam’ received command 24

2019-03-20 18:52:50.914 [ome.event.ItemCommandEvent] - Item ‘LivingRoom_Light1’ received command ON

2019-03-20 18:52:51.081 [vent.ItemStateChangedEvent] - LivingRoom_Light1 changed from OFF to ON

==> /var/log/openhab2/openhab.log <==

2019-03-20 18:52:51.108 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule ‘apertura’: Could not cast NULL to java.lang.Number; line 11, column 11, length 25

// global vars are defined at the begin of the file
var Timer tApertura = null

rule "apertura"
when 
    Item LivingRoom_Light1 changed to ON
then
    var Number x = 0
    if(DimmerCam.state instanceof Number)
        x = ((DimmerCam.state as Number) * 0.24).intValue
    tApertura?.cancel
    tApertura = createTimer(now.plusSeconds(x)) [|
        LivingRoom_Light1.sendCommand(OFF)
    ]
end
1 Like

You need to enable autoupdate for DimmerCam, otherwise the commands you send via habpanel won’t update the item.

1 Like

I enable autoupdate ad it works.
Perfect.
But I saw you have changed completly the last rule. Why? Is it not good?

Yes, I changed it slightly :slight_smile:
There are some situations which will cause your rule to fail:

  • DimmerCam.state is not of Type Number (e.g. it is NULL) → null-pointer exception
  • Light is switched off an on while timer is running → two instances of the same code are planned and there is no way to stop the first timer
  • .plusSeconds() needs Integer as input → wrong type exception if x is not of type Integer
1 Like

Ok thank’s