Hello,
I want to monitor the voltage of a 400V battery.
I receive messages from the battery via MQTT in the following format:
MQTT topic: battery/info
Payload:
{
"battery_voltage": 3500,
"stat_batt_power": 2905,
"temperature_min": 12.000,
"temperature_max": 14.000,
"cell_max_voltage": 3812,
}
As you can see the battery voltage is a 4 digit number and the real voltage is 3 digits
How do I display 350V?
Can someone help me with the division formula?
Thank you
JimT
(jimtng)
February 9, 2024, 4:25pm
2
The super easy way to do this is by setting up your Thing channel with unit="dV"
(deci Volt), 3500 deci Volt = 350 Volt
Then set your item’s unit to V
. Voila!
You can alternatively use some sort of transformation but the above is the easiest way to solve it.
PoC:
thing = things.build do
thing "mqtt:topic:test", bridge: "mqtt:broker:mosquitto" do
channel "test", "number", config: { stateTopic: "test/test", unit: "dV" }
end
end
items.build do
number_item "TestV", thing:, channel: "test", unit: "V"
end
updated(TestV) { logger.info "TestV updated to #{event.state}" }
# mosquitto_pub -h 192.168.1.10 -t test/test -m 3500
02:23:36.100 [INFO ] [ation.jrubyscripting.rule.test1.rb:11] - TestV updated to 350 V
2 Likes
Mherwege
(Mark Herwege)
February 9, 2024, 4:27pm
3
dV
is correct, but it stands for deci Volt, not deca Volt (which is 10 Volt and written as daV
).
If using UoM (or QuantityType) it’s very easy
Use unit = "dV"
Maybe you’ll have to write it with an asterisk: unit = "d*V"
as DeciVolt isn’t a very common unit .
Link a Number:ElectricPotential
Item and set this to unit="V"
and State Description Pattern="%.1f V"
to get the electric potential with one decimal (350.0 V
)
EDIT: deci is abbreviated with D, not d, as d is the abbreviation for day. So it has to be Channel unit="DV"
I use dV and d*V but i have the same value now 3410.0V
JimT
(jimtng)
February 9, 2024, 4:33pm
7
Your item needs to be Number:ElectricPotential and set the unit on the Item to V
As said… You’ll have to use Number:ElectricPotential and you’ll have to set the unit for the Item, too.
I created new item but now my measurement is NULL
i created an item like this and the value displayed is 3410
Number:ElectricPotential Batt_Voltage "Tesla Battery Voltage [%d]"
in this way my displayed value is 34100.0
my items:
Number:ElectricPotential Batt_Voltage "Tesla Battery Voltage [%.1f dV]"
my sitemap:
Text item=Batt_Voltage label="Tesla Battery Voltage [%.1f dV]" icon="batterylevel"
There is no option to use a transformation file somehow with JSONPATH?
JSONPATH:$.battery_voltage ????????
rlkoshak
(Rich Koshak)
February 9, 2024, 5:32pm
11
There’s no file to use. What would you put in this file? $.battery_voltage
is the path. It’s all JSONPATH needs.
Make sure you’ve installed the JSONPATH add-on.
NilsOF
(Nils)
February 9, 2024, 6:02pm
12
What? Decivolt?
That must be something java programmers have dreamt up!
More seriously; divide or multiply by ten to get what you want.
Why? It’s really easy…
The only thing to do is not to mess up…
As a thing within a things file:
Bridge mqtt:broker:broker "My broker" [
// broker config
] {
Thing topic tesla "Tesla" {
Channels:
Type number : vBat "battery voltage" [ stateTopic="battery/info", transformationPattern="JSONPATH:$.battery_voltage", unit="DV" ]
}
}
Item within an items file:
Number:ElectricPotential TeslaBattery "Tesla Battery" <battery> {channel="mqtt:topic:broker:tesla:vBat", unit="V", stateDescription=""[pattern="%.1f V"]}
Sorry, did a quick test and it’s DV, not dV (as d is already reserved for Day)
Please change Channel unit to DV and Item unit to V.
Mherwege
(Mark Herwege)
February 9, 2024, 8:03pm
15
Is that MQTT specific. i don’t think it is in general.
Well my guess is, the documentation is wrong
Did you see my posting? DV instead of dV should do the trick…
my items:
Number:ElectricPotential Batt_Voltage "Tesla Battery Voltage" <battery> {channel="mqtt:topic:ce2219a49a:6f071898da:Battery_Voltage", unit="V", stateDescription=""[pattern="%.1f V"]}
That’s really strange as I’ve tested here.
Which version of openHAB? My test system is openHAB4.1.1 Release Build.