I would like to know if we are day or night

Objective

My original aim was to turn on the external lights when the portal opens but only at night!

Testing

I tested several integrations:

I create a binary _sensor It's dark

Obviously, this binary _sensor takes two values:

  • on: when it's dark
  • off: when it's daylight

The most purists (who seek the difficulties) will be able to enjoy themselves and create a second binary _sensor for the "it is daylight". 😉

Simplissime code of this binary_sensor, to be created in binary_sensor.yaml thinking that it has been declared in configuration.yaml:

- platform: tod name: "It's Night" unique _id: binary_sensor.nuit after: sunset after_offset: "-00:10" before: sunrise before _offset: "+00:10"

after_offset and before_offset at 10min, it is not for the sake of perfection, it is to remember the syntax of this parameter that I want to adjust it in the future.

  • Thank you @ἶჰმ#6938 for the helping hand.

Use of this binary _sensor in a condition

My objective is to switch on the external lights when the gate opens ONLY when it takes night, so here is the added condition:

I do not put the condition on the closure, because if there is an adventurous day between the opening and the closing, the lights would remain on.