Displaying Number:Temperature in HabPanel (SOLVED)

So I know this topic has been covered extensively and there are plenty of threads to google and search, however I cannot seem to make this work :frowning:

I have HabPanel using a weather widget.

image

I’m using Ecobee to pull my weather values, however it keeps displaying everything in Fahrenheit, and not Celsius.

Number Temperature “Temperature [%.2f °C]” {channel=“ecobee:thermostat:*****************:runtime#actualTemperature”}

Note: I’ve tried changing the item to a Number:Temperature, however (as we know) that doesn’t display in HabPanel correctly, especially if you’re using a widget template

(HTML code)

{{'%.1f' | sprintf:itemValue('Temperature')}}

So, to get around this, I tried creating a rule

rule “Temperature Fix”
when Item Temperature received update
then
var fahrenheit = Temperature.state as Number

var Number celsius = ((fahrenheit - 32) / 1.8)

Temperature.postUpdate(celsius)

end

Problem is, as the screenshot shows above, it shows the result as -40 for some reason.
I feel like the syntax of my rule is correct - but I can’t understand why this is working?

Any help would be immensely appreciated :slight_smile:

Does your rule ever stop?

  • You trigger when Temperature has received an update.
  • You then do some calculation
  • You then update Temperature

Doesn’t that re-trigger the rule?

1 Like

As @hafniumzinc said, you start a neverending loop here… You can add a virtual item and update/display that one or you could try to use sendCommand within your rule (instead postUpdate). Afaik sendCommand should not trigger „received update“

That’s correct, but with caveats, according to the docs, and maybe the quickest fix in this scenario.

Don’t just try this at random. What type is the channel that the binding offers? Use the matching Item type, and then we’ll sort out whats left.

If you edit this, you’ll need to wait for the next ecobee update for it to get straightened out. Show us your events.log of a change if you are still having trouble.

holy shit were you guys ever right…bruuuutal loop right now

So i guess the first thing to do is stop this from happening.
Flip mentioned doing a SendCommand instead of postUpdate?

It does indeed actually specify as a Number:Temperature
However, if I do this, then I get a syntax error and it doesn’t display correctly

Okay, so I got it working now (sort of)

A few things, as Flip mentioned, SendUpdate instead of PostUpdate is the way to go.
Also I should not have triggered on a Recieved update (which is why it was causing the loop)

The newcode (below) that I used was to run a cron expression every 10 min (will probably widen this timeframe)

rule “Temperature Fix”
when
Time cron "0 */10 * ? * * "
then
var fahrenheit = Temperature.state as Number
var Number celsius = ((fahrenheit - 32) / 1.8)
sendCommand(Temperature, celsius)
logInfo(“EventLog”, “Adjusting Temperature”)
end

Problem is I can’t seem to do multiple numbers at once (if I try to do all of the min and max temperatures)

rule “Temperature Fix”

when

Time cron "0 * * ? * * "

then

var fahrenheit = Temperature.state as Number

var Number celsius = ((fahrenheit - 32) / 1.8)

sendCommand(Temperature, celsius)



var fmin1 = Temp_Min0.state as Number

var Number cmin1 = ((fmin1 - 32) / 1.8)

sendCommand(fmin1, cmin1)

var fmin2 = Temp_Min1.state as Number

var Number cmin2 = ((fmin2 - 32) / 1.8)

sendCommand(fmin2, cmin2)



var fmin3 = Temp_Min2.state as Number

var Number cmin3 = ((fmin3 - 32) / 1.8)

sendCommand(fmin3, cmin3)

var fmin4 = Temp_Min3.state as Number

var Number cmin4 = ((fmin4 - 32) / 1.8)

sendCommand(fmin4, cmin4)

var fmax1 = Temp_Max0.state as Number

var Number cmax1 = ((fmax1 - 32) / 1.8)

sendCommand(fmax1, cmax1)

var fmax2 = Temp_Max1.state as Number

var Number cmax2 = ((fmax2 - 32) / 1.8)

sendCommand(fmax2, cmax2)

var fmax3 = Temp_Max2.state as Number

var Number cmax3 = ((fmax3 - 32) / 1.8)

sendCommand(fmax3, cmax3)

var fmax4 = Temp_Max3.state as Number

var Number cmax4 = ((fmax4 - 32) / 1.8)

sendCommand(fmax4, cmax4)

logInfo("EventLog", "Adjusting Temperature")

end

Then i get an error like this

2020-10-24 02:04:00.002 [ERROR] [ntime.internal.engine.ExecuteRuleJob] - Error during the execution of rule ‘Temperature Fix’: An error occurred during the script execution: Could not invoke method: org.eclipse.smarthome.model.script.actions.BusEvent.sendCommand(org.eclipse.smarthome.core.items.Item,java.lang.Number) on instance: null

I suspect it has to do with the fact that I’m trying to do too many at once?
I wish there was a more graceful way to accomplish this.

This wasn’t a random suggestion.
If you have now corrected your Item to type Number:Temperature, may we see the event log of an update from your device?
... [%.2f °C]
This is you telling openHAB “I would like temps in °C”
So long as you use a Number:Temperature Item type, which understands °C, the binding will oblige and auto-convert for you.

Once the Item state is correct, we can look at you HABpanel issue.

No, the loop is caused by manipulating the same Item as you started with. It’s just bad practice. The cron would still not do what you want - 10mS after your conversion, the device might update the Item again.

But you don’t need the rule at all.

I didn’t actually change it to Number:Temperature because that causes it to not display correctly.

Here is the problem if I use it as a Number:Temperature.

image

Yes it shows up correctly as Celsius in the PaperUI, however it does not in HABpanel.

Also changing this does not seem to show anything in the logs

2020-10-24 14:11:47.740 [INFO ] [ipse.smarthome.model.script.EventLog] - Fixing Weather Item Condition3
2020-10-24 14:12:25.884 [INFO ] [panel.internal.HABPanelDashboardTile] - Stopped HABPanel
2020-10-24 14:12:25.913 [INFO ] [panel.internal.HABPanelDashboardTile] - Started HABPanel at /habpanel

Excellent, now the Item is correct we can work on your UI.
Have you got rid of the rule yet?

As already said, it will not until/unless the Item changes, but then you get the advantage of seeing what the Items state is.
You do have to look in events.log file.

It’s going to be something like 17.0 °C
Note, that is not a number, it is a quantity type. The °C is all part of the value.

Armed with that information you can review what you are doing in HABpanel. Trying to format as float for example is not going to work, because it’s not just a number.
If you tick “use server supplied format” or whatever it is, you should get the [%.2f °C] form that you asked for in your Item definition.

Yes, I got rid of the rule :slight_smile:
Okay so I do see the item changes in the events log

(chilly today lol)

2020-10-24 15:29:47.413 [vent.ItemStateChangedEvent] - BasementTemp changed from 20.8888888888888888888888888888889 °C to 20.7777777777777777777777777777778 °C
2020-10-24 15:29:47.434 [vent.ItemStateChangedEvent] - Temperature changed from 5.6666666666666666666666666666667 °C to 21.1111111111111111111111111111111 °C
2020-10-24 15:29:47.434 [vent.ItemStateChangedEvent] - Temperature changed from 21.1111111111111111111111111111111 °C to 5.6666666666666666666666666666667 °C
2020-10-24 15:29:47.434 [vent.ItemStateChangedEvent] - Condition1 changed from Possible Rain to Possible drizzle in the morning.
2020-10-24 15:29:47.434 [vent.ItemStateChangedEvent] - Condition2 changed from Light Rain to Light rain until evening.
2020-10-24 15:29:47.435 [vent.ItemStateChangedEvent] - Condition3 changed from Cloudy to Mostly cloudy throughout the day.
2020-10-24 15:29:47.724 [vent.ItemStateChangedEvent] - Condition2 changed from Light rain until evening. to Light Rain
2020-10-24 15:29:47.725 [vent.ItemStateChangedEvent] - Condition3 changed from Mostly cloudy throughout the day. to Cloudy
2020-10-24 15:29:47.725 [vent.ItemStateChangedEvent] - Condition1 changed from Possible drizzle in the morning. to Possible Rain

As for the HABPanel, I should mention that I’m using a templated widget (HTML-code) not a dummy frame. Hence, I do not have the option to “use server supplied format”

(Line 12 is the one that isn’t working as a Number:Temperature)

I will say that it displays correctly if I use a dummy frame, but I’m trying to get it working in this nice widget that displays multiple temperatures.

Excellent.

Can’t help with that; apart from a reminder that the value from Item state is not a float number , it comes with the units text. So %.1f is not going to work in your sprintf.

Well after everything, I have solved the problem.

image

The key is how the HTML code in my template was defined.

This is how I had to format it to take into account a float number.
Here is the modified code

{{'%.1f' | sprintf:itemValue('Temperature').split(' ')[0]}}

After the Temperature, I had to add

.split(’ ')[0]

This allowed it to work correctly.
Marking as Solved.

You could of course have used %s, as you already specified the decimals you wanted in the item [state presentation]