- Platform information:
- Hardware: _Raspberry Pi 2
- OS: Raspbian Stretch
- Java Runtime Environment:
openjdk version “1.8.0_152”
OpenJDK Runtime Environment (Zulu Embedded 8.25.0.76-linux-aarch32hf) (build 1.8.0_152-b76)
OpenJDK Client VM (Zulu Embedded 8.25.0.76-linux-aarch32hf) (build 25.152-b76, mixed mode, Evaluation) - openHAB 2.2:
- Issue of the topic: LogInfo String Formatting not working
- Please post configurations (if applicable):
- Items configuration related to the issue
- Sitemap configuration related to the issue
- Rules code related to the issue
** logInfo prints the format codes, not the formatted variable values **
rule "Family Room Temperature Check"
when
Item Sensor_FF_FR_Temperature changed
then
if (Sensor_FF_FR_Temperature.state != null && Sensor_FF_FR_Temperature.state != NULL) {
if (fr_temp_lastvalue != null && fr_temp_lastvalue != NULL) {
logInfo("DefaultRules",
"Temperature changed from %1$.1f°C to %1$.1f°C",
fr_temp_lastvalue,
Sensor_FF_FR_Temperature.state
)
if (19 <= fr_temp_lastvalue && fr_temp_lastvalue <= 22) {
if (Sensor_FF_FR_Temperature.state < 19) {
loginfo("DefaultRules", "Alarm: Family Room temperature too low")
sendMail("chris@mydomain.net", "Temperature Alarm",
"Temperature in Living Room is below threshold")
}
if (22 < Sensor_FF_FR_Temperature.state) {
loginfo("DefaultRules", "Alarm: Family Room temperature too high")
}
}
}
fr_temp_lastvalue = Sensor_FF_FR_Temperature.state
}
end
- Services configuration related to the issue
- If logs where generated please post these here using code fences:
2020-01-19 09:34:58.943 [INFO ] [.smarthome.model.script.DefaultRules] - Temperature changed from %1$.1f°C to %1$.1f°C
2020-01-19 09:35:01.007 [INFO ] [.smarthome.model.script.DefaultRules] - FR Luminance now [150], was [146]
2020-01-19 09:36:00.500 [INFO ] [.smarthome.model.script.DefaultRules] - Temperature changed from %1$.1f°C to %1$.1f°C
I lifted the format code from the example in the openhab 2.2 documentation (2nd example, last line). I know I can always convert the variable to a string but I prefer the style of this method (although I like Python 3.6+ formatting the most).
So it looks like it supposed to work in 2.2.
Thanks in advance,
Chris
NB: The temperature range is pretty narrow so I can test the rule based on my thermostat setback. The range will be widened for actual use, to protect the house against a failed or runaway furnace when on vacation.