Cron with var time

This way off calling a cron is not working. Is there a solution for?

item.
String WarmtepompAvondTijd

Time cron WarmtepompAvondTijd.state

No. You cannot set a cron trigger using the state of an Item like that or any way really. At least not with Rules DSL.

And this is definitely an XY Problem. What are you trying to accomplish?

Hi ,

I believe You can use jruby language to do it.
Here is an example ,

rule "DateTime Trigger" do
  at My_DateTimeItem
  run do |event|
    logger.info "Triggered by #{event.item} at #{event.item.state}"
  end
end

Take a look at,

Br
Artur

Note the code linked there is old. The line that says require 'openhab' needs to be removed to be compatible with the new library.

But as @rlkoshak said, if you explain your situation in more detail, we could give you better suggestions in how to tackle it. There’s usually more than one way to do things

For heating temperature setting I use 4 cron triggers to set the temperature during the day. I set the temperature of my Daikin heat-pump over the Onecta binding. I can set the heating temperatures easily with sitemap but I want to be able to change also the timings to tune the system without coding.

So use DateTime Items which can be updated using a sitemap using an Input element or MainUI using an input element with the type set to time.

You can trigger your rules using the time is <item> timeOnly trigger and the rule will run at the time stored by the DateTime Item’s State, ignorning the date portion of the DateTime.

1 Like

What do you think from timeline picker? You has a visualisation of intervals of temperature setpoints and it’s pretty easy to change. AND you keep the overview about your settings.

btw. You can set weekday’s and weekend different in one widget.

Thanks. I can set the hour and minute inside the sitemap

Setpoint item=WarmtepompNachtUur minValue=0 maxValue=23 step=1 label="Uur"
Setpoint item=WarmtepompNachtMinuut minValue=0 maxValue=59 step=1 label="Minuut"

and set a DateTime item

rule "Update Nachtstand Tijd"
when
    Item WarmtepompNachtUur changed or
    Item WarmtepompNachtMinuut changed
then
    val uur = WarmtepompNachtUur.state as Number
    val minuut = WarmtepompNachtMinuut.state as Number
    val nieuweTijd = now.withHour(uur.intValue).withMinute(minuut.intValue).withSecond(0).withNano(0)
    val nieuweTijdUTC = nieuweTijd.withZoneSameInstant(java.time.ZoneOffset.UTC)
    val dateTimeState = new DateTimeType(nieuweTijdUTC.toString())
    WarmtepompNachtTijd.postUpdate(dateTimeState)
end

but the trigger is not working. Can you advise

rule "Warmtepomp Nachtstand Trigger"
when
    Time is WarmtepompNachtTijd timeOnly
then
end

Try with lowercase time like in @rlkoshakā€˜s example.

I’d definitely consider using a an Input element with an input hint of ā€œtimeā€ instead of a bunch of setpoints and then needing to build a DateTime from that. Sitemaps | openHAB

Textual Rules | openHAB is the docs for the trigger. It actually looks correct based on the docs.

Your rule doesn’t have any body though, how do you know it’s not triggering?

There was a time that the trigger wasn’t added to Rules DSL but it should be there for at least 4.1 if not earlier.

I have something similar…

var nieuweTijd = ZonedDateTime.now.withHour(uur).withMinute(minuut).withSecond(0).withNano(0)
var DateTimeType dateTimeState = new DateTimeType(nieuweTijd) 
WarmtepompNachtTijd.postUpdate(dateTimeState)

and WarmtepompNachtTijd should be DateTime Type

give it a try.

But… why have the 2 numbers? you can directly set the DateTime Item in your MainUI/Sitemap
Sitemap:

Input item=WarmtepompNachtTijd label="Set Time [%1$tH:%1$tM]" inputHint="time"  

greets.

Thanks. I wasn’t aware of this but this is perfect with one line of code.

I don’t understand why but with the time setting solution from BaschtlwaschtlSebastian this is working