knowthelist / fhem-tablet-ui

UI builder framework for FHEM
MIT License
148 stars 84 forks source link

Dimmer widget is using the wrong reading when "data-dim" is set #158

Closed medlor closed 7 years ago

medlor commented 8 years ago

Hello,

first of all: Thanks for this great work!

Background: I have got fibaro light dimmers. In my szenario I would like to be able to turn it ON and OFF BUT also be able to set a specific dim value. For this hardware the reading for the dim value can be found in "reportedState". But to set this dim value the command "set X dim Y" must be used! This hardware also supports "set X on|off", but I am using the "dim 0|99" command instead, because it is easier to use.

My current definition is:

I have found no way to have my scenario working. Looking in the source code I can see: js/widgetdimmer.js: ~Line 55: valueChanged: function(elem,v) { var device = elem.data('device'); localStorage.setItem(this.widgetname+""+device, v); if ( elem.data('famultibutton').getState() === true || elem.data('dim') !== '' ){ if (elem.hasClass('FS20')){ v = this.FS20.dimmerValue(v); } var valStr = elem.data('set-value').replace('$v',v.toString()); var reading = (elem.data('dim') !== '') ? elem.data('dim') : elem.data('set'); //next lines is a fix it for me: //var reading = (elem.data('set') !== '') ? elem.data('set') : (elem.data('dim') !== '') ? elem.data('dim') : '' ; var cmd = [elem.data('cmd-value'), device, reading, valStr].join(' '); setFhemStatus(cmd); TOAST && $.toast(cmd); } },

In my opinion and according to your README the command should always be using the "data-set" value (if set) and not the "data-dim" value. Therefore data-set (if set) should always override data-dim.

If perhaps there are reasons for this code (use cases?), I propose to create an additional attribute, which should be used for "dimmer" functionalities: data-get-dim: previous "data-dim" attribute data-set-dim: new attribute the be used to set dimmer (if not set use data-get-dim attribute)

Best Regards Tobias

medlor commented 7 years ago

Workaround: Create a read-able user reading with the same name as the already existing write-able one (here: "dim").

Example for fibaro: attr Licht userReadings dim:reportedState.* {ReadingsVal($name,"reportedState","0")}