- Platform information:
- Hardware: Raspberry pi 3
- OS: OpenHabian
- Java Runtime Environment: 11
- openHAB version: Openhabian 3.0.1
- Issue of the topic:
I am trying to create a rule that will let me toggle lights on or off when i press one button (The same button) The button is actually a tasmota device that has a keypad, and the lights are tasmotized 3stone rgb lights using hue emulation.
The keypad part works (when i press a button, i can see the event in openhab logs, and i can also trigger rules. The problem appears to be with the rule itself. I am using the following code:
var currentvalue;
currentvalue = itemRegistry.getItem('Bedsidelamp').getState();
if (currentvalue == "OFF") {
events.sendCommand('Bedsidelamp', 'ON');
} else if (currentvalue == "ON") {
events.sendCommand('Bedsidelamp', 'OFF');
}
After troubleshooting, i realized that getState() is returning a numeric value that appears not to be the ON/OFF state. For example, as i am writing this, the value shows as a card in the interface and it is set to 0.23
I have also tried to query one of the points of the equipment (_Color). I did this because the interface does show an on/off switch. So i modified the code to do run the following when the rule is triggered.
var currentvalue;
currentvalue = itemRegistry.getItem('Bedsidelamp_Color').getState();
logger.error(currentvalue)
brightness = currentvalue.getBrightness();
if (brightness == 0) {
events.sendCommand('Bedsidelamp_Color', 'ON');
} else if (brightness > 0) {
events.sendCommand('Bedsidelamp_Color', 'OFF');
}
However, it does not look to me like the brightness in the HSV object color necessarily corresponds to the ON/OFF state. And i could not find out what could.
The issue that i am facing is that the values returned do not appear to represent the on/off state. So what happens is, that i press the button once, and nothing happens (It appears that the rule sends an OFF command to a light that is already off), and then, the next time the command works. Almost like something (Maybe the itemregistry) looses state at some point. Before troubleshooting that further, i want to make sure that i am querying the correct states.
In summary. how can i query the ON/OFF state of a light bulb? I understand this might depend on the light bulb, but if it does, how can i find out how to query it in my specific light bulb?
I wanted to post some code about how the light bulb is created, but i didn’t find how in OH3. What i can say is, the light was automatically discovered by OH3, and it is an equipment of the semantic class “Lightbulb”.
Any help is appreciated.
Thanks!
- Please post configurations (if applicable):
-
Items configuration related to the issue: The light has two Points, Color, and Color Temperature.
-
Sitemap configuration related to the issue
-
Rules code related to the issue
-
Services configuration related to the issue
-
- If logs where generated please post these here using code fences: