Datetime sunset in magic

I have read in the documentation that I can use sunset in rules but can I use it in Magic also?

Well… Magic is just a ui term in the app that groups rules and scripts.

There are plugins like daylightsensor and datetime which provide sunset/sunrise information in form of things. You can use that in rules and scripts to do stuff based on that. Alternatively there’s the

And what thing do I have to create to use datetime?

There’s 2 that come to my mind right now…

For once the “today” thing, which fetches daylight information among others from some webapi. Then there’s the daylightsensor which only provides sunset/sunrise information but does it completely offline by calculating it based on your position.

Also iirc the openweathermap plugin would provide a daylightsensor based on the openweathermap api.

1 Like

I use the daylight from weather thing and it works amazing.
First you have to add a thing with daylight property, like “today” or “weather”.
After that, in your Magic, you have to define your daylight something like I did it bellow:

ThingState {
        id:daylight 
        thingId: "{cf39106a-aeed-40c9-a712-92fc2dfe9164}" // this thingId shoud be unique
        stateName: "daylight"
}

And finally, you can use the daylight variable in you Magic scripts whenever you want:

        if(daylight.value == true){
           do somehting
        } else {
            something else
        }
2 Likes

Thanks @flax1k for this nice example.

I use it with a rule that will turn on some moodlight in my living room. There’s also a rule template for that. Which will appear automatically once a daylightsensor is set up.

2 Likes

Hi,
i activated the daylightsensor thing and added Magic as you mentioned above.
The Rule is working… and the christmas lighting switches on when it gets dark and vice versa.

1 Like