Sitemap for a variable


I’m running OpenHab 2 on a Windows 10 computer. Everything is working fine but there is something I would like to be able to set dynamically. Here’s my setup.

I use Chamberlain MyQ bindings to query my garage door, have alert when it’s open/closed and remotly open/close it. This work fine. I also have a rule. When my garage door is open, it create a timer for 30 minutes. The timer trigger a close command on the garage door so I don’t leave it open by mistake. All the check in the rules are in place to prevent a false trigger (when the door is closed, the timer is canceled). I also have a switch item called garageDoorPermaOpen that when true prevent the activation of the timer (for summer day’s where it’s hot and I want to work with the garage door open).

All of this work fine. Where I’m trying to have some fine tuning is in the value of the timer. I would like to set a setpoint on my sitemap, with value from 1 to 60 (or more, then maximum value isn’t a problem) that is used by the timer. On the sitemap, it would be “auto-close door timer” and this value would be the value used by the timer. I tried creating a setpoint without any binding, didn’t worked. I’m unsure what to do here and how to have it update the timer in consequence.

Thank you

The timer expects an integer, you should be able to do it like:
(YourSetpoint_NumberItem.state as DecimalType).intValue

Thanks for the input. My problem now is that the setpoint doesn’t display any value even when I press up or down. I did set a min, max and step value. :frowning:

How did you set it up (Item and Sitemap)?

I do the same thing for a sleep timer for my audio system for background noise.

Here is the item definition:

Number Sleeptime

Here the sitemap entries:

Setpoint item=SleepTime label="Sleep time  [%d min]" minValue=1 maxValue=1000 step=1
Switch item=SleepTimer label="Start sleep timer" mappings=[ON="GO"]

And the rules file:

var Timer bedroomSleepTimer = null

rule SqueezeBedroomSleepTimer  
        Item SleepTimer received command ON
        val turnOffTime = now.plusMinutes((SleepTime.state as DecimalType).intValue)
        if(bedroomSleepTimer != null)
        bedroomSleepTimer = createTimer(turnOffTime, [| sendCommand(sq_bedroom_control, PAUSE)])
1 Like

Thanks, I’ll try that tonight. I think it’s my item definition that wasn’t working even if I used a Number, but maybe there was something else.

Thank you it work perfectly. Is there a way to set a default value for when the service reset?

Yeah there is. You can initialize items on startup either from persistence or with a hardcoded value. I haven’t gotten around to it yet and haven’t done it before so you will have to check the forum for how exactly to do it.

I order the get back the last value of all items persist all items using MapDB using the strateies everychange and restoreonstartup. That way MapDB will persist every change on each item and restore it on startup.
Set a default after start:
Use a rule that is triggered on system started in which you set the desired value.

Only one of both is needed!

I’ll have to check on how persistence works. Right now I’ve used a default with the system started event and it work great. I’ll check for the persistence later, it will be better that way.

Thank you!