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
I have HabPanel using a weather widget.
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?
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“
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.
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.
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
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.
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.