I need a template which returns true for any time between sunset - 2 hours and sunset + 0.5 hours. For all other times, it should return false. So, if the sunset is at 7:45 PM, the template should return true between 5:45 PM and 8:15 PM.
I was wrongly assuming that offset in sunset would do this but on reading documentation, it turns out that offset from sunset is just a point in time. I am looking for a time span.
This method will not return the correct value after sunset, because the sensor attribute will have rolled forward to the next day. This will cause sunset120 < time to be false.
That is why @123 included the time() method in his final expression. It avoids having the date roll over mess up the time comparison… at the cost of a few seconds of accuracy.
But from sunset until midnight, now() will be today and sunset will be tomorrow… so the 30 minutes after sunset will be false when they should be true.