-
Notifications
You must be signed in to change notification settings - Fork 639
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Openhab 2.4 MQTT: Dimming 0-100% instead of 0 to255 #1460
Comments
Out of interest, I built a version and included
Although this works using espurna and openHAB, to get the Google assistant to recognise the device, I had to set the device in the '.items' file to a DIMMER rather than NUMBER type. The problem was, when espurna MQTT received the command from openHAB, espurna seemed to convert it to a decimal number <= 1. This meant at 100%, the channel#0 recevied the value 1, not 100. |
Can you give an example of MQTT interaction? Lights module stores channel and brightness values in kv storage as |
I have setup another openHAB channel that uses the mqtt brightness rather than channel#0 so as to not effect my current setup too much. Using 'REST API' to send to numerical value to the openHAB item, the openHAB log file shows:
espurna's log shows:
Trying to send a number greater than 100 fails, I guess as its a 'Dimmer' item rather than a 'Number' item. Perhaps although openHAB's log says its sending 100 or 75, it may only be sending the percentage 1 or 0.75 rather than a number. |
I have just tried the app 'MQTT Dash' as a separate MQTT input. That just sends the numerical value to the topic. This works fine. Sending any number between 0 and 255 is received by espurna, shows that value and updates the value on the status screen correctly. It must be an openHAB issue. |
So does that mean transformation on openhab side is possible after-all? Re:
Log is confusing, why it is a 0...1 suddenly. MQTT only handles the integer part of the number, so anything after the dot is silently dropped (at least it is how I remember String::toInt() aka strtol error handling works for partially parsed strings). |
I think I read once about transformation issues directly with the mqtt add-on binding, but I guess by using proxy items openHAB will use those values via the proxy item to the mqtt binding. I'll try and get some more espurna logs if that helps? |
If it helps, I've been using openhab and mqtt (mosquito) with espurna for a while now... This is how I handle the dimmers:
It's probably not all that pretty, but it seems to work ok for me with either Alexa or Google Assistant. Edit: trimming some spaces |
Thanks @ColinShorts . Using the .js transform code above, would that require me to use the JSON payload function of espurna mqtt instead of the standard single mqtt entries? I'm unfamiliar with the |
Judging from the |
I could have provided a bit of context, and a different example. The device is an intermitech quinled esp-01 based 2 channel dimmer. I'm only using a single channel in ceiling lights although that doesn't really matter in this context. Here is an example showing two way communication:
As everything had been going through openhab, and I have no physical controls that talk to the devices directly*, openhab keeps track of the values.
|
I think that may have been due to the light being turned off at the time. See output below:
The strange thing is, by changing brightness via mqtt both brightness and channel#0 values get updated and that can be seen in the output:
But the webUI still shows the original 255 value for channel#0, even after refreshing the page. I then changed the webUI slider from 255 to 136 (just a random position) and the output gives:
Changing channel#0 slider back to 255 sets channel#0 back to 52:
Should channel#0 follow brightness? Should channel#0 not be used at all and just use brightness control for a single dimmer? |
From a openHAB and espurna integration point of view, by setting the definitions |
I should add to this thread, using openHAB rules and proxy items my dimmer works fine. Percent is converted to number (0-255) and sent to channel#0, and channel#0 (0-255) changes are converted to percent. With Google I can request a percent change and the corresponding 0-255 value is sent to the device via openHAB and mqtt. What I was looking for (so was @flashy02) was a direct interaction with openHAB and espurna when the item is of type 'DIMMER'. openHAB item type 'COLOR' uses percentage HSB values to send a value between 0-100 without having to use rules or transformations but a single channel dimmer only uses the 0-255 values. |
I have setup a rule to output the value of the 'DIMMER' item to a log entry. Regardless of whether its set to log as 'string' or 'number' changing the value to 50 logs 50, 75 logs 75 and 100 logs 100 etc. In espurna's logs it shows 0.50000000, 0.75000000 and 1.00000000. Disabling mqtt on espurna (to stop the value being set to 0 by the stateTopic update) and then querying the openHAB items state value using REST API, it reports the 50, 75, 100 etc values. I don't know how the percent value of 50 from openHAB gets interpreted as 0.5 by espurna? |
Hm. So looking at the mqtt.generic readme:
https://community.openhab.org/t/mqtt-homie-dimmer-item-value-scale/77362/38
So the dimmer should probably work even with 0...255 when setting min= max= and step= attributes colorRGB / colorHSB is another matter, but does it not work like that already? espurna/code/espurna/light.ino Lines 267 to 270 in a2599de
HSB(V) matches with the 360,100,100 syntax mentioned in the readme of the mqtt.generic RGB is inherently 0...255 |
All working!! Read on and thanks for your assistance. :-) I upgraded from 2.4.0 to 2.5.0M6 but that made no difference. Although the openHAB item is set as a dimmer, I had the thing/channel defined as a 'NUMBER' type. I have changed it to a 'DIMMER' type and espurna now sees the correct numerical value:
This works correctly now I have set the 'thing' type to 'DIMMER' instead of 'NUMBER'. I set the min/max to 0/255 with a step of 1. Using the 'SLIDER' item within the sitemap (which is a 0-100% slider), espurna receives the 0-100% value between 0-255. |
Yeah, that would not work with a single channel device. But do we still want to have configurable min= and max= from ESPurna side? Maybe even combining brightness and value max into one setting. WebUI can receive the same changes as #1941, adjusting input type=range limits |
Personally, with the knowledge I now have, it doesn't probably matter. I read multiple times about DIMMERS in the openHAB setup, but it took a while to sink in what the actual configuration does setting up min/max/step values in the openHAB 'THING' to match the hardware configuration. I guess from a new user point of view 0-100 makes more sense than 0-255. Is it something that can be added to the espurna v2 code and adjusted in the webUI rather than re-compiling using #defines? Could 'Light' offset type values for colour and brightness be adjusted similar to the calibration settings used when setting up a power monitoring device? That way, if someone really wanted to, they could force their light to, dim to or brighten to a fixed value while their home automation software would still use the 0-100% range. |
This can be closed as there is a native way of doing this:
|
Closing via #1460 (comment) & https://github.com/xoseperez/espurna/wiki/MQTT#openhab |
Hello everybody,
with the new Openhab release 2.4 a new MQTT binding is used, so the workaround of using an transformation for a channel/dimmer before publishing a dimming-value is no longer possible.
With this, only values from 0-100% where published from a Dimmer-Item.
In the past i thought several times about it, why it is possible to use HSB values for a RGB channel where it is normal to use a value between 0-100% for the brightness-channel, but if I want to use the channel directly, it is neccesary to use a value between 0-255 (8bit).
The Feature request would be, to get a switch in the web-interface to change the channels/brightness from 0-255 behavior to 0-100% behaviour for MQTT, so no transformation in Openhab is neccesary.
Best regards Flashy
The text was updated successfully, but these errors were encountered: