Hello OpenHab teachers,
I managed to monitor the voltage and temperature of a 400V battery
Can someone help me write two rules to be able to disconnect the auxiliary charger?
Close the Charger Relay when the battery voltage is higher than 395V
Close the Charger Relay when the battery temperature is higher than 40 degrees Celsius
rule "Activate Charger Relay" do
changed Batt_Voltage, Cell_Temp_Max
run do
ChargerRelayJ20.ensure << (Batt_Voltage.state > 395 | "V") || (Cell_Temp_Max.state > 40)
end
end
Or if you prefer to make it as succinct as possible (one line)
Hi, thanks for the help, but I couldn’t get it to work. I want to use these rules in case of emergency - as an additional safety system. I want to start the charger in other conditions.
Now it’s on and I want to turn it off if the battery voltage reaches 395.
I tested with a relay for the lights and reduced the maximum battery voltage threshold, but it doesn’t seem to work.
rule "Activate Charger Relay" do
changed Batt_Voltage, Cell_Temp_Max
run do
LuminaJ20.ensure << (Batt_Voltage.state > 360 | "V") || (Cell_Temp_Max.state > 40)
end
end
You can’t run the rule manually. The rule has to be triggered by a change in value of Batt_Voltage. So try changing Batt_Voltage state to 400 V, that should trigger the rule.
Assumption:
You’ve created this rule in a file located in <OPENHAB_CONF>/automation/ruby/ANY_FILENAME.rb
As you can see, my battery is charging now and has 364V
in the script I will set the relay to stop at 366 V
I think that’s the best way to test it, but it doesn’t work
rule "TURN OFF charger relay" do
changed Batt_Voltage
run do |event|
LuminaJ20.ensure.off if (event.state > 366 | "V")
end
end
You can manually change an item state. Unless you have other rules, it shouldn’t affect anything.
You can change an item state either using the Karaf console, or simply adding this line at the end of your rule and saving it again:
rule "TURN OFF charger relay" do
changed Batt_Voltage
run do |event|
LuminaJ20.ensure.off if (event.state > 366 | "V")
end
end
# The following lines are for testing only
sleep 1
Batt_Voltage.update 370 | "V"
The battery has not reached 366V yet - it has 63KW and I charge with approximately 3KW.
Should I change like this?
rule "TURN OFF charger relay" do
changed Batt_Voltage
run do |event|
LuminaJ20.ensure.off if (event.state > 366 | "V")
end
end
sleep 1
Batt_Voltage.update 367 | "V"
Changing the state of the Batt_Voltage item will not physically change anything in the real world outside openhab. So it won’t actually physically make your actual Battery to have that voltage.
You can set the Batt_Voltage state to 100000V and that won’t matter.
It just affects inside Openhab’s state and will trigger our rule
You don’t have to wait if you just added those two extra lines. I promise it won’t cause any harm.
Here’s a better rule. It should do what you want, plus log the event but only if the event actually caused the relay to be turned off. It won’t log anything if the relay was already off.
rule "Shutdown charger when threshold is reached" do
changed Batt_Voltage, to: proc { |state| state > 377 | "V" }
changed Cell_Temp_Max, to: proc { |state| state > 40 }
run do |event|
turned_off = ChargerRelayJ20.ensure.off
logger.info "#{event.item} (#{event.state}) exceeded the threshold. Shutting down charger" if turned_off
end
end
If you can have a threshold that’s inclusive, e.g. batt_voltage >= XX instead of batt_voltage > XX, then the to: condition above can use a simpler Ruby Range like this:
# This threshold is inclusive when using ruby range's lower bound
VOLTAGE_THRESHOLD = 377 | "V"
rule "Shutdown charger when threshold is reached" do
changed Batt_Voltage, to: (VOLTAGE_THRESHOLD..)
changed Cell_Temp_Max, to: (40..)
run do |event|
turned_off = ChargerRelayJ20.ensure.off
logger.info "#{event.item} (#{event.state}) exceeded the threshold. Shutting down charger" if turned_off
end
end
rule "Shutdown charger when threshold is reached" do
changed Batt_Voltage, to: proc { |state| state > 377 | "V" }
changed Cell_Temp_Max, to: proc { |state| state > 40 }
run do |event|
turned_off = ChargerRelayJ20.ensure.off
logger.info "#{event.item.label} (#{event.state}) exceeded the threshold. Shutting down charger" if turned_off
end
end
Will this close the relay if one or both conditions are met correctly?