Naive how-to question

Hello,

I am a newbee trying to use Openhab to control a Rachio-based watering system, At this time, I have successfully installed the Rachio binding and I am already able to perform some basic control of my sprinklers through Openhab.

One thing that I do not like in my current setup is that the watering duration needs to be specified in a number of seconds rather than a number of minutes. The fact is that the Rachio binding provides me with a runtime duration number in seconds that I can set at will before issuing a run command.

My items and sitemap files include the following:

‘’’
/// Items
Number Default_Zone_Runtime {channel=“rachio:device:1:009D6BBDE9CA:runTime”}
Switch Irrigation_Zone_1 “Zone Gazon” [ “Switchable” ] {channel="rachio:zone:1:009D6BBDE9CA-1:run
‘’’
‘’’
//Sitemap
Setpoint item=Default_Zone_Runtime label=“Watering time (seconds): [%d]” icon=“time” minValue=300 maxValue=3600 step=300
Switch item=Irrigation_Zone_1 icon=“faucet”
‘’

The setpoint Default_Zone_Runtime allows the user to specify a number of seconds (in increments of 300, i.e. 5 minutes). Then the user can start the sprinklers for that particular duration.

What I would like, is for the user to specify the runtime in minutes rather than seconds.The user would be able to specify a number of minutes and that number would then be converted to seconds before updating.Default_Zone_Runtime. Could you please help me identify one or more good ways of achieving that result?

I understand that for most of you this must be a trivial question, but I have not been able to figure out the answer using the available documentation and my very poor knowledge of java.

Many thanks.

Many thanks

I suggest submitting a PR for the binding to use Number:Time rather than just Number.

In the meantime, you could do this using a proxy Item.

You do not have to show every Item on the sitemap - so you can ‘hide’ the real duration Item behind the scenes.
You can create Items with no links to any real device or property, generally called proxy or virtual Items. Such Items can be shown and interactive in your UI, examined and manipulated by rules, just like any other Item.

So you can create a ‘minutes’ Item, put on your UI with a Setpoint. A rule can listen for commands to it (user clicks) and do maths on the command to convert minutes to seconds. Then the rule can command the real duration Item with seconds.

also i’m not a java nerd…i’m pretty shure there is a function to convert numbers, but no clue how this works. but in such a case, i often “workarround” with alias items and a rule like:

var ConvertMinSec = 0

rule “alias_item”
when
Item your_alias_item_in_sitemap changed
then
ConvertMinSec = ( your_alias_item_in_sitemap * 60)
Number Default_Zone_Runtime.postUpdate(ConvertMinSec)
}
end

Maybe it would be possible to multiplicate direct into the “postUpdate” brackets…?

So, you have to create a “alias” item in your item file, and then make this item visible instead the original one.

Hope, this helps you to solve the issue

Hi Andreas,

Thanks for the suggestion.
I added the following item in my items file:

‘’’
Number Zone_Runtime_Min

‘’’
And I also added a way to change its value in my sitemap:

‘’’
Setpoint item=Zone_Runtime_Min label=“Temps d’arrosage (minutes): [%d]” icon=“time” minValue=5 maxValue=60 step=5
‘’’

And I added your proposed rule in my rule file:

‘’’
var ConvertMinSec = 0
rule “Convertir minutes en secondes”
when
Item Zone_Runtime_Min changed
then
ConvertMinSec = (Zone_Runtime_Min * 60)
Number Default_Zone_Runtime.postUpdate(ConvertMinSec)
end
‘’’

But when the rule file is read, I get the following message:

‘’’
020-07-12 11:58:19.498 [INFO ] [el.core.internal.ModelRepositoryImpl] - Validation issues found in configuration model ‘default.rules’, using it anyway:
This expression is not allowed in this context, since it doesn’t cause any side effects.
‘’’

And when I try to set the value of Zone_Runtime_Min, I get this other message:

‘’’
2020-07-12 12:17:54.184 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule ‘Convertir minutes en secondes’: Unknown variable or command ‘*’; line 26, column 22, length 21
‘’’

Line 26 happens to be the following one:

‘’’
ConvertMinSec = (Zone_Runtime_Min * 60)
‘’’
and column 22 is the point where ‘Zone_Runtime_Min’ begins.

Cheers,

Pierre

That’s an Item, so it is the state of the Item that you are usually interested in.

ConvertMinSec = Zone_Runtime_Min.state * 60

If you want the binding to do anything with that, like send it to a device, you will need to send a command rather than update the Item state.

Number Default_Zone_Runtime.sendCommand(ConvertMinSec)

Thanks. I did modify my rule as you siuggested:

‘’’
rule “Convertir minutes en secondes”
when
Item Zone_Runtime_Min changed
then
ConvertMinSec = Zone_Runtime_Min.state * 60
Number Default_Zone_Runtime.sendCommand(ConvertMinSec)
end
‘’’

Unfortunately, I am still receiving the very same error messages:

When the rule file is read:

‘’’
2020-07-12 12:51:11.430 [INFO ] [el.core.internal.ModelRepositoryImpl] - Validation issues found in configuration model ‘default.rules’, using it anyway:
This expression is not allowed in this context, since it doesn’t cause any side effects.
‘’’

And when I change the value of Zone_Runtime_Min:

‘’’
2020-07-12 12:52:46.853 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule ‘Convertir minutes en secondes’: Unknown variable or command ‘*’; line 26, column 21, length 27
‘’’

– Pierre

Rules are picky old things. It has to work out which operator we mean by something like ‘*’ based on the preceding variable. In this case, it’s an Item state, which doesn’t give the rules parser enough of a clue. We need to be more explicit -

ConvertMinSec = (Zone_Runtime_Min.state as Number) * 60

Wow: this one was not quite obvious. I got it working now. Many thanks!

great! sorry, my example was really not perfect… but thats what the community is for! rgs

Right! Thanks anyway.

please put your code in code fences because this is goobly gook

OK, my basic OH racho interface is working, but there is still something missing.

At this time, when I trigger my sprinklers through the Rachio app rather than through OH, then OH does not get notified that the relevant sprinklers are being triggered.

Is this what the “URL callback” and “port forwarding” stuff discussed in the Rachio binding documentation are about? In other words, if I do manage to set up the portforwarding stuff correctly, does this mean that OH and the Rachio app will become synchronized?