Use of scripts

Hello all.
I’m trying to get started with scripts… Is it correct understood that it can be used for etc. a simple heating controller (later be build more complex) something where I can call the script with some variables and get something return…

Could be actual temperature, mode, valve…

Then inside the script:
If temp1 < temp 2 and mode = 1 then return valve on or off?

So I only need to call the script:
Call script - then how to assign the in/output?

I think what you want is rules. Rules are triggered when a condition is met, typically the state of an item changes, although you can use other conditions too such as when a time of day is reached.

Within the rule, you can then put any logic you want and have it fire off actions to set the value of something. So, an example of something for you could be

rule "Heating on"
when
	Item HallTemperature changed
then
	if(HallTemperature.state < 18)
	{
		sendCOmmand(Boiler, ON)
	}
end

That rule would fire every time the HallTemperature changes. It will then check if its below 18 degrees, and if so tell the Boiler to turn ON.

Hello…
Yes i understand the rules, but at time I’ll develop the heating control - that’s why I wanna do it in a script - so I only need to change the code in the script, then it’ll be present in all rooms when I call the script from a rule :slight_smile:

There is no direct way to pass vars to a script.

You may want to look into lambdas. While you cannot pass vars to a script not can you get a return value (I think), you can do both with a lambda. The only limitation though is that only rules in the same file as the lambda can call it.

Thanks - exactly what I was looking for :slight_smile: