"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/prometheus/client_golang/prometheus/promhttp"
+ // sunrise/sunset activation
+ "github.com/nathan-osman/go-sunrise"
+
// color correction
"github.com/lucasb-eyer/go-colorful"
"golang.org/x/exp/slices"
},
[]string{"location"},
)
+ // used for NightOnly calculations later, Seattle def
+ sunriseLat float64 = 47.608013
+ sunriseLon float64 = -122.335167
)
// structs
LastMotion time.Time
LastState bool
Dummy bool `yaml:"Dummy"`
+ NightOnly bool `yaml:"NightOnly"`
logger logr.Logger
sendChannel chan helper.RabbitSend
switches []*Switch `yaml:"Switches"`
relay.LastUpdate = relay.LastUpdate.Add(-staleDuration)
}
+func sunIsUp(localTime time.Time) bool {
+
+ year, month, day := localTime.Date()
+ // get the sunrise/sunset times for the current day
+ rise, set := sunrise.SunriseSunset(
+ sunriseLat, sunriseLon,
+ year, month, day,
+ )
+ oneDay, _ := time.ParseDuration("24h")
+ fudgeDuration, _ := time.ParseDuration("1h")
+ year, month, day = localTime.Add(-oneDay).Date()
+ risePrevious, setPrevious := sunrise.SunriseSunset(
+ sunriseLat, sunriseLon,
+ year, month, day,
+ )
+ logger.V(4).Info("Sunrise and sunset times", "sunrise", rise, "sunset", set, "localTime", localTime)
+ logger.V(4).Info("Previous sunrise and sunset times", "sunrise", risePrevious, "sunset", setPrevious)
+
+ if (localTime.After(rise.Add(fudgeDuration)) && localTime.Before(set.Add(-fudgeDuration))) || (localTime.After(risePrevious.Add(fudgeDuration)) && localTime.Before(setPrevious.Add(-fudgeDuration))) {
+ return true
+ } else {
+ return false
+ }
+
+}
func (relay *RGBRelay) shouldDim() bool {
- curTime := time.Now().UTC()
+ localTime := time.Now()
+ curTime := localTime.UTC()
+ // dim _only_ if during sun-up in current day, otherwise use regular logic
+ if relay.NightOnly {
+ if sunIsUp(localTime) {
+ return true
+ }
+
+ }
dimmingDuration := time.Duration(relay.DimmingTimeout) * time.Second
if relay.LastMotion.Add(dimmingDuration).Before(curTime) {
return true
devices = append(devices, newdoordevice("data_door"))
// hex devices (super custom)
- devices = append(devices, newhexdevice("0x7e6af7fefff95560", "Downstairs Test"))
+ //devices = append(devices, newhexdevice("0x7e6af7fefff95560", "Downstairs Test"))
+ devices = append(devices, newhexdevice("0x526af7fefff95560", "Downstairs Test"))
devices = append(devices, newesp32wifidevice("esp32.sensor_info", ""))