Flip a switch in the event of a severe weather warning (DWDUnwetter Binding)


I use the DWDUnwetter Binding to receive weather warnings. According to different warnings (heat, wind, thunderstorm), I want to turn on different switches. After the warning ends, the switch should turn off. For example, you can use the switch to close windows or open blinds. To do so, I created the follwing rule and items:


var Timer Gewitter_Start_Timer = null
var Timer Gewitter_Ende_Timer = null

rule "DWD_Unwetter_Warnung"
        Channel 'dwdunwetter:dwdwarnings:zuhause:updated1' triggered NEW
        val String strMessage = (WarningzuhauseTyp.state.toString).toLowerCase

        // Gewitter
            val millis_Gewitter_Start = (WarningzuhauseGueltigAb.state as DateTimeType).zonedDateTime.toInstant.toEpochMilli - now.millis

            val millis_Gewitter_Ende = (WarningzuhauseGueltigBis.state as DateTimeType).zonedDateTime.toInstant.toEpochMilli - now.millis
            createTimer(now.plusSeconds(5), [ |

                var int Gewitter_Start = (WarnungTimerGewitterStart.state as Number).intValue
                var int Gewitter_Ende = (WarnungTimerGewitterEnde.state as Number).intValue

                if (Gewitter_Start_Timer !== null) {
                    logInfo("WarnungStart", "Timer aktualisiert, Beginn der Gewitterarnung in " + Gewitter_Start + " Minuten")
                else {logInfo("WarnungStart", "Beginn der Gewitterarnung in " + Gewitter_Start + " Minuten")
                    Gewitter_Start_Timer = createTimer(now.plusMinutes(Gewitter_Start), [ |

                if (Gewitter_Ende_Timer !== null) {
                    logInfo("WarnungEnde", "Timer aktualisiert, Ende der Gewitterwarnung in " + Gewitter_Ende + " Minuten")

                else {logInfo("WarnungEnde", "Ende der Gewitterwarnung in " + Gewitter_Ende + " Minuten")
                    Gewitter_Ende_Timer = createTimer(now.plusMinutes(Gewitter_Ende), [ |
        else return

Unwetter.items (in addition you will need will need some of the demo.items from DWDUnwetter Binding):

Switch DWD_Gewitter "Starkes Gewitter"
Number WarnungTimerGewitterStart "Beginn Warnung in Minuten [%d]"
Number WarnungTimerGewitterEnde "Ende Warnung in Minuten [%d]"

You can add multiple switches depending on the type of warning.

As you will probably see right away, I am not a programmer, so I did all of this through trial and error. That is why I am happy to receive any suggestions on how to do this even better.

For example, I have no idea how to implement it if the warning duration is suddenly extended.

EDIT: I found out how to do this, a lot easier than I thougt…

Best regards,

Okay, since I got an

Could not cast [...] to org.eclipse.smarthome.core.library.types.DecimalType

error from time to time, I had to change

val Integer Timer_Start = (WarnungTimerGewitterStart.state as DecimalType).intValue


val Number Timer_Start = (WarnungTimerGewitterStart.state as Number).intValue

And since the rule is sometimes executed faster than the calculation, I had to add a little “calculation pause”.