Modify the time from Habpanel

Hi
I want a widget to modify from habpanel the hours, minutes and seconds.
Can you help me?

What time do you want to set? There is no direct widget to chose time or date, but of course you could build some items to store time (and date) as separate numbers, which then could be changed through setpoint or even a slider.

I have not experience of html.
I want to set from the habpanel an hours to go up the shutter automatically.

Really? There are much better ways to automate roller shutters (Astro Binding - setup earliest, latest time to open/close the roller shutter, setup an offset, let the roller shutters open & close depending on sunrise/sunset.)
If you really want it like in the last century :wink: simply define four Number items:

Group Shuttertime
Number ShutterUpMin "Minute [%d]" (Shuttertime)
Number ShutterUpHour "Hour [%d]" (Shuttertime)
Number ShutterDownMin "Minute [%d]" (Shuttertime)
Number ShutterDownHour "Hour [%d]" (Shuttertime)

Then setup four Widgets to change the Items (step 1, minimum 0, maximum 23 or 59 depending on the item)
Setup a rule:

// define all global var or val at the beginning of the file
var Timer tShutterOpen = null
var Timer tShutterClose = null

rule "set shutter timers"
when
    Time is midnight or
    Member of Shuttertime changed
then
    if(Shuttertime.members.filter[m | m.state ! (instanceof Number)].size > 0) {
        logWarn("shutterTimer","Some item is not of type Number!")
        return;
    }
    val nUp = (ShutterUpMin.state as Number) + (ShutterUpHour.state as Number) * 60
    val nDown = (ShutterDownMin.state as Number) + (ShutterDownHour.state as Number) * 60
    if(nUp > now.getMinuteOfDay) {
        tShutterOpen?.cancel
        tShutterOpen = createTimer(now.withTimeAtStartOfDay.plusMinutes(nUp), [ | 
            Shutters.sendCommand(UP)
        ])
    }
    if(nDown > now.getMinuteOfDay) {
        tShutterClose?.cancel
        tShutterClose = createTimer(now.withTimeAtStartOfDay.plusMinutes(nDown), [ | 
            Shutters.sendCommand(DOWN)
        ]) 
    }
end

Theory of working:

  • The rule is triggered at midnight and if one of the items changed its status.
  • as a first step, the rule checks if all time items are set to a number value. If not, the rule is cancelled immediately.
  • Second step is to calculate the chosen time (in Minutes) for up and down.
  • Third step is to calculate if up time has passed for today.
  • Fourth step ist to set a timer according to the calculated time. As there is a chance that there already was a running timer, we first cancel the timer, if scheduled (tShutterOpen?.cancel)
  • Do the steps three and four for the down command.

EDIT: Changed rule code (added missing brackets)

I’m studing the rule :grinning:
but if i run it i have
2019-03-21 14:18:51.771 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model ‘settare_orario - Copia.rules’ has errors, therefore ignoring it: [6,49]: no viable alternative at input ‘instanceof’

The error is here

if(Shuttertime.members.filter[m | m.state ! instanceof Number].size > 0) {
        logWarn("shutterTimer","Some item is not of type Number!")
        return;

I think the “!” is the error. Is it true?

I have a question:
What kind of elements i must set for i 4 shuttertime elements?

i report you the situation

the items are

I modified the code:

rule "set shutter timers"
when
    Time is midnight or
    Member of Shuttertime changed
then
    if(Shuttertime.members.filter[m | m.state instanceof Number].size > 0) {
        logWarn("shutterTimer","Some item is not of type Number!")
        return;
    }
    val nUp = (ShutterUpMin.state as Number) + (ShutterUpHour.state as Number) * 60
    val nDown = (ShutterDownMin.state as Number) + (ShutterDownHour.state as Number) * 60
    if(nUp > now.getMinuteOfDay) {
        tShutterOpen?.cancel
        tShutterOpen = createTimer(now.withTimeAtStartOfDay.plusMinutes(nUp), [ | 
            LivingRoom_Light2.sendCommand(ON)
        ])
    }
    if(nDown > now.getMinuteOfDay) {
        tShutterClose?.cancel
        tShutterClose = createTimer(now.withTimeAtStartOfDay.plusMinutes(nDown), [ | 
            LivingRoom_Light1.sendCommand(OFF)
        ]) 
    }
end

The panel is

The problem is that when i set the value so

i have this
2019-03-21 16:14:01.833 [ome.event.ItemCommandEvent] - Item ‘ShutterUpHour’ received command 16

2019-03-21 16:14:02.448 [ome.event.ItemCommandEvent] - Item ‘ShutterUpMin’ received command 25

2019-03-21 16:14:02.478 [vent.ItemStateChangedEvent] - ShutterUpMin changed from 21 to 25

==> /var/log/openhab2/openhab.log <==

2019-03-21 16:14:02.500 [WARN ] [.smarthome.model.script.shutterTimer] - Some item is not of type Number!

==> /var/log/openhab2/events.log <==

2019-03-21 16:14:03.106 [ome.event.ItemCommandEvent] - Item ‘ShutterDownHour’ received command 20

2019-03-21 16:14:03.124 [vent.ItemStateChangedEvent] - ShutterDownHour changed from 1 to 20

==> /var/log/openhab2/openhab.log <==

2019-03-21 16:14:03.139 [WARN ] [.smarthome.model.script.shutterTimer] - Some item is not of type Number!

==> /var/log/openhab2/events.log <==

2019-03-21 16:14:03.838 [ome.event.ItemCommandEvent] - Item ‘ShutterDownMin’ received command 0

2019-03-21 16:14:03.850 [vent.ItemStateChangedEvent] - ShutterDownMin changed from 1 to 0

==> /var/log/openhab2/openhab.log <==

2019-03-21 16:14:03.877 [WARN ] [.smarthome.model.script.shutterTimer] - Some item is not of type Number!

NOTE: the items ShutterDownMin, ShutterDownHour, ShutterUpMin, ShutterUpHour of course are not linked with sonoff but i use it only to determine the time to turn on or off.
The items linked with sonoff are LivingRoom_Light1 e LivingRoom_Light2

Please change the line to

    if(Shuttertime.members.filter[m | m.state ! (instanceof Number)].size > 0) {

the ! is the boolean NOT. Sorry for forgetting the brackets…

this is the new error

2019-03-21 18:20:37.613 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model ‘settare_orario2.rules’

2019-03-21 18:20:37.621 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model ‘settare_orario2.rules’ is either empty or cannot be parsed correctly!

2019-03-21 18:20:38.770 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model ‘settare_orario2.rules’ has errors, therefore ignoring it: [6,50]: no viable alternative at input ‘instanceof’

[6,67]: extraneous input ‘)’ expecting ‘]’

The problem is alway on “instanceof number”

Aaaaaargh… sorry… :blush:

if(Shuttertime.members.filter[m | !(m.state instanceof Number)].size > 0) {

Well, shift work and early service…

:joy::joy:
I try again

Now i have
2019-03-21 18:35:44.014 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule ‘set shutter timers’: An error occurred during the script execution: Could not invoke method: org.joda.time.DateTime.plusMinutes(int) on instance: 2019-03-21T00:00:00.000+01:100:

I’m not sure that my items are good.

look my situation:

this is how i set the four widgets:




Can you advise me how i have to modify the elements of the panel?

Look at ShutterUpHour, You accidentally typed ShutterUPHour.

Time for some additional logging:

rule "set shutter timers"
when
    Time is midnight or
    Member of Shuttertime changed
then
    if(Shuttertime.members.filter[m | !(m.state instanceof Number)].size > 0) {
        logWarn("shutterTimer","Some item is not of type Number!")
        Shuttertime.members.filter[m | !(m.state instanceof Number)].forEach[ m| 
            logWarn("shutterTimer","{} : {}",m.name,m.state.toString)]
        return;
    }
    Shuttertime.members.forEach[ m| 
        logInfo("shutterTimer","{} : {}",m.name,m.state.toString)]
    val nUp = (ShutterUpMin.state as Number) + (ShutterUpHour.state as Number) * 60
    val nDown = (ShutterDownMin.state as Number) + (ShutterDownHour.state as Number) * 60
    logInfo("shutterTimer","nUp: {}; nDown: {}",nUp,nDown)
    if(nUp > now.getMinuteOfDay) {
        tShutterOpen?.cancel
        tShutterOpen = createTimer(now.withTimeAtStartOfDay.plusMinutes(nUp), [ | 
            LivingRoom_Light2.sendCommand(ON)
        ])
    }
    if(nDown > now.getMinuteOfDay) {
        tShutterClose?.cancel
        tShutterClose = createTimer(now.withTimeAtStartOfDay.plusMinutes(nDown), [ | 
            LivingRoom_Light1.sendCommand(OFF)
        ]) 
    }
end

now i have this

2019-03-21 19:55:06.756 [INFO ] [.smarthome.model.script.shutterTimer] - ShutterUpMin : 10

2019-03-21 19:55:06.762 [INFO ] [.smarthome.model.script.shutterTimer] - ShutterUpHour : 20

2019-03-21 19:55:06.767 [INFO ] [.smarthome.model.script.shutterTimer] - ShutterDownMin : 4

2019-03-21 19:55:06.771 [INFO ] [.smarthome.model.script.shutterTimer] - ShutterDownHour : 3

2019-03-21 19:55:06.781 [INFO ] [.smarthome.model.script.shutterTimer] - nUp: 1210; nDown: 184

2019-03-21 19:55:06.791 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule ‘set shutter timers’: An error occurred during the script execution: Could not invoke method: org.joda.time.DateTime.plusMinutes(int) on instance: 2019-03-21T00:00:00.000+01:00