Rule: Variable übergeben?
Verfasst: 31. Dez 2017 14:25
Hallo
aus dem eng Forum habe ich mir folgende Regel kopiert:
Ich möchte nun die Variable "currPeriod" in einer zweiten Regel nutzen, wie übergibt man diese?
Im Moment gibt so einen Fehler: The name 'currPeriod' cannot be resolved to an item or type
Gruß
PS: Beim obrigen Script bekomme ich den hinweis: The type TimeOfDay is deprecated
aus dem eng Forum habe ich mir folgende Regel kopiert:
Code: Alles auswählen
import org.joda.time.* // I don't think this should be required but I get errors when I don't include it
// System started to calculate the current time period in case the time period changed when OH was down
rule "Get time period for right now"
when
System started or
Time cron "0 0 6 * * ? *" or // Morning start
Item Sunrise_Event received update ON or // Day start
Item Evening_Event received update ON or // Evening start
Time cron "0 0 22 * * ? *" // Night start
then
// Sleep for just a bit to make sure we are not exactly on the time period boundary
Thread::sleep(50)
// Get the time period start times for today
val morningStart = now.withTimeAtStartOfDay.plusHours(6).millis
val sunriseStart = new DateTime((Sunrise_Time.state as DateTimeType).calendar.timeInMillis)
val eveningStart = new DateTime((Twilight_Time.state as DateTimeType).calendar.timeInMillis)
val nightStart = now.withTimeAtStartOfDay.plusHours(22).millis
// Calculate the current time period
var currPeriod = "Night"
if(now.isAfter(morningStart) && now.isBefore(sunriseStart)) currPeriod = "Morning"
else if(now.isAfter(sunriseStart) && now.isBefore(eveningStart)) currPeriod = "Day"
else if(now.isAfter(eveningStart) && now.isBefore(nightStart)) currPeriod = "Evening"
// Send the current time of day if it has changed
if(TimeOfDay.state.toString != currPeriod){
TimeOfDay.sendCommand(currPeriod)
}
end
Code: Alles auswählen
...
then
if (currPeriod != "Day") ...
Gruß
PS: Beim obrigen Script bekomme ich den hinweis: The type TimeOfDay is deprecated