Temperature widget doesn't set line

The temperature widget is using all the style information I give it. It is also displaying the current temperature numerically, but not graphically. See below:


Here is the widget definition:

south_bedroom_temperature:
  widget_type: temperature
  widget_style: "background-color: $background_color;"
  entity: sensor.<some-sensor>
  settings:
    minValue: 65
    maxValue: 95
    width: 270
    height: 320 
    majorTicks: [65,70,75,80,85,90,95]
    highlights: [{'from': 65, 'to': 70, 'color': 'rgba(0,0, 255, .3)'},{'from': 74, 'to': 95, 'color': 'rgba(255, 0, 0, .3)'}]

Are you sure the sensor is returning a numeric value rather than a string? “75.4” is not the same as 75.4.

Yeah, I cast it as a float. It would be silly if it cared, but that doesn’t seem to be the problem.

I also tried casting it as an int. In hass, the source sensor shows 76.4, the int sensor shows 76, and the HAD temperature widget shows it as 76.0. So I get the decimal place whether I want it or not.

Here’s a funny symptom: I left a page open to the dashboard overnight and today the red line shows the current temperature. Then, when the page refreshed, the red line dropped back down to the bottom. Auto-recompile, maybe? I could dig into the widget and see if it’s defaulting to the lowest value instead of the last value, I suppose.

I appear to have solved the problem - it’s in the basetemperature.js code. The method drawChart instantiates a new LinearGauge each time with all default parameters.

  1. Instantiate new LinearGauge with default parameters (Celsius)
  2. Sets the gauge value to entity state value (state.state)
  3. Updates the gauge with the user widget values (Fahrenheit, in my case)

Something about the parameters leaves the value alone for the text display but zeroes out the red bar. This is a bug in LinearGauge, maybe. At any rate, a one line change seems to fix it. Change the second to last line of basetemperature.js from this

self.gauge.value = state.state

to

if (null == self.parameters.settings.value){
                self.parameters.settings.value = state.state  
}

There may be a good reason for instantiating a new gauge object every time, I don’t know. But given that’s what it does, this change causes it to do the right thing at the first parameter update, yet still allows the user to override the value if so desired.