Expose day/night from custom sensor template

Hi, I have a custom sensor template to figure out whether it is day or night and I want to expose that data to the knx bus.

- platform: template
  sensors:
    day_night:
      value_template: >
        {{ 1 if is_state('sensor.period_of_day','up') else 0 }}

My idea was to expose that entitiy to the bus via

expose:
  - type: binary
      entity_id: sensor.day_night
      address: "6/4/1"

But I get the error message “mapping values are not allowed here in “/config/knx/expose/expose.yaml”, line 2, column 14” which points to the entitiy id of the expose.

So my question would be how can I expose the mapping? Or is there another way to do that?

Hi :wave:!
Your indentation is wrong. Yaml is quite picky about this.

expose:
  - type: binary
    entity_id: sensor.day_night
    address: "6/4/1"

Oh you are right I completely missed that late at night. Thank you.

I installed the sun integration and managed to send a binary value to my KNX bus. The group address “6/1/1” represents if it’s day with true and night with false which can be used by dimming actuators or similar.

I used the following expose template.

expose:
  - type: binary
    address: "6/1/1"
    entity_id: sun.sun
    attribute: elevation
    value_template: "{{ value > 0 }}"
1 Like