Rule to turn OFF the charger relay the when the battery voltage reaches 395V

As an aside:

For a “Normally Open” relay, “closing the relay” means energising the relay by providing current to the electromagnet, and that’s usually done by turning something on.

I guess in your case it’s the opposite. Turning the Switch item off is the effect you wanted, which somehow “closes the relay”?

Now my relay is ON and the script you proposed should turn it OFF

Correct.

I also agree with you, but OpenHab does not seem to agree with us.
I set the maximum voltage to 367V and now it has reached 368V.
But guess what? Not working




It seems that he fell in love with the mains charger

But in your rule screenshot your threshold is > 368 V That means your voltage needs to be 369 V for it to trigger

I’m waiting - no problem, I’d be happy if it works

OK Don’t change the rule again, just wait.

One thing I changed in the logging is #{event.item.label} => #{event.item} so that if your item has no label, it will print the item name.

But change it later - once it passed your test



The relay is still ON and the voltage has risen to 369V

This rule switches off ChargerRelayJ20 switch, not LuminaJ20

Sorry, you are right


But now I want to ask you.
If I set the maximum voltage limit to a lower value than the current one and run the script. Shouldn’t the relay turn off?

Did you save this rule inside a file, and not create it via the UI?

I created the rule and then I edited in it everything you sent me :slight_smile:

The trigger only executes when the value of Batt_Voltage or Cell_Temp_Max is changing. If you want it to also run as soon as the script you could add extra code to make it do that.

I am now not sure how you’ve created this rule.

Did you create it inside a file and only using the UI to view it?
This rule is meant to be created and saved in a file, not created through the UI.

File-based rules cannot be edited through the UI. You can view it, but it should have a lock icon and doesn’t let you edit it on the UI.

Yours doesn’t have those things, and the fact that the title is different, suggests that you’ve created the rule incorrectly, so it won’t work.


Like this and i can edit it if I click on it

OK that’s not the correct way to do it.

Here’s the correct way:

Create a file using a text editor of your choice and paste the rule into it. I see that you’re using .items file - it’s similar. Save the file in conf/automation/ruby/shutdown_charger.rb

If saved correctly, you should be able to see the rule in the Main UI under Settings → Rules. You should see the lock icon and you won’t be able to edit it using the Main UI.



I need to see the rule in openhab scripts ?

You should see it here:

  • Rules have triggers, optional conditions, and execution
  • Scripts consist only of the execution code. It does not include / define any triggers/conditions.

In and by itself, a Script doesn’t do anything for you. Something / someone needs to actually execute it for it to run. It’s a more advanced concept where you can execute a 'Script` from inside your rule.

I have been using openhab since 2018 and have never needed to use ‘Scripts’. Everything I do are done through creating ‘rules’.

Here is the “Scripts” section of my actual openhab instance for my home:


And here is the “Rules” section of my actual openhab instance:


did not appear here

Can you show me where your .things and .items files are stored? Maybe you’ve used the wrong path.