from core.rules import rule
from core.triggers import when
from core.actions import ScriptExecution
from java.time import ZonedDateTime as DateTime
@rule("Turn on ZWaveNode089FGS222DoubleRelaySwitch2X15KWSwitchBinary1 after motion sensor is triggered", description="Turn on Flood light after motion is detected", tags=["Tag 1", "Tag 2"])
@when("Item ZWaveNode104SP816SP816MotionSensorAlarmMotion changed")
def ZWaveNode104SP816SP816MotionSensorAlarmMotion(event):
if items["Naplemente_Kapcsolo"] == ON and items["Overwind"] == OFF:
if items["ZWaveNode104SP816SP816MotionSensorAlarmMotion"] == ON:
events.sendCommand("ZWaveNode089FGS222DoubleRelaySwitch2X15KWSwitchBinary1", "ON")
ScriptExecution.createTimer(DateTime.now().plusSeconds(120), lambda:(ZWaveNode104SP816SP816MotionSensorAlarmMotion_2(OFF)))
def ZWaveNode104SP816SP816MotionSensorAlarmMotion_2(event):
if items["ZWaveNode104SP816SP816MotionSensorAlarmMotion"] == OFF:
events.sendCommand("ZWaveNode089FGS222DoubleRelaySwitch2X15KWSwitchBinary1", "OFF")
else: ZWaveNode104SP816SP816MotionSensorAlarmMotion(ON)
Hello, I am currently migrating from OpenHAB 2.5 to 3.0. I really like the semantic model but I am struggling with migrating from Jodatime to Java Time API. I am not a programmer and guess there is a trivial solution. How do I translate these few lines?
var Number hour = now.getHourOfDay
var Number day = now.getDayOfWeek
var Number month = now.getMonthOfYear
I am finalizing a rule for OH3 and struggling with the conversion. Probably an easy one for the community to give me the right hint.
> rule "Biotonne Erinnerung"
> when
> Time cron "0 30 9 * * ? *"
> then
>
> val ZonedDateTime zdt = ZonedDateTime.now()
> val ZonedDateTime pickupDateCompare = zdt.toLocalDate().atStartOfDay(zdt.getOffset())
> val GarbagePickup = (garbage_collection_bioabfall.state as DateTimeType).getZonedDateTime()
> val FuturePickupDate = pickupDateCompare.plusDays(2)
>
>
> if( FuturePickupDate > GarbagePickup ) {
> val telegramAction = getActions("telegram","telegram:telegramBot:Telegramxxxxx")
> telegramAction.sendTelegram(xxxxxxxxx, "Denke an die Biotonne!!! Die Abholung ist am " + garbage_collection_bioabfall.state.toString()+".")
> logInfo ("Biotonne", "Denke an die Biotonne!!! Die Abholung ist am " + garbage_collection_bioabfall.state.toString()+"." )
>
> }
> end
The rule is working but I am struggling to understand how to format the Date of the output to make it dd:mm:yyyy like in the UI. this is how the output currently looks like:
Denke an die Biotonne!!! Die Abholung ist am 2021-02-08T00:00:00.000+0100
displayState.toString is not supported here in the rule. I am getting an error message.
Hello, now I’ve managed to get my holiday script to work. Now I get an error in the log
Script execution of rule with UID ‘holly-1’ failed: Text ‘2021-4-4T00: 00: 00.000Z’ could not be parsed at index 5 in holly
Please help
var year = "2021"
var day = "4"
var month = "4"
//Day
if (day.length == 1) {
day = "0" + day
}
//Month
if (month.length == 1) {
month = "0" + month
}
var easterSunday = ZonedDateTime.parse(year + "-" + month +"-" + day + "T00:00:00.000Z").toLocalDate
logInfo("date", "date {}", easterSunday)
//outputs date 2021-04-04
So they are not strings, but integers. It’s quite hard to fix rules that we can’t see and you do not tell us what the moving parts are.
If you would like to go back to using OH2, you can. It hasn’t gone away and it will not stop working.
So, if your values are integers we can use a completely different approach.
var year = 2021
var day = 4
var month = 4
var easterSunday=LocalDate.now.withYear(year).withMonthOfYear(month).withDayOfMonth(day)
logInfo("date", "date {}", easterSunday)
//outputs date 2021-04-04