I want to broadcast the Dawn and Dusk moments in time to KNX, were I used to control main phases of lighting: Day, Evening and Night.
The KNX Time-DPT is exclusively reserved for the actual time, so I want to express Dawn and Dusk in minutes form 00:00 using DPT time_period_min
I wrote the following configuration:
pack_astro:
knx:
expose:
# Dawn in minutes after 00:00
- type: time_period_min
address: "0/4/0"
entity_id: sun.sun
attribute: sensor.sun_next_dawn
value_template: >-
{% set t = strptime(value, '%a %b %d %H:%M:%S %Z%z %Y') %}
"{{ (t.hour * 60) + t.minute }}"
This runs fine, up to the value part. When I enter a fixed value, this will be broadcasted to KNX on a read request. However I don’t get any value regarding the next_dawn, so I can’t split the time into hours and minutes either. Logs are “Error rendering value template for KNX expose sun.sun__sensor.sun_next_dawn”.
Are you sure this should work at all? Tried to do an automation to just send the time of sunset/sunrise when it changes, but whatever I enter when using type time it seems home assistant is not allowing to send anything but system time
Fehler: Invalid payload for knx.send service: ConversionError description=“Could not serialize DPTTime (10.001): Invalid value for KNXTime: string indices must be integers, not ‘str’” value=“sensor.next_sunset”/
knx.send s payload doesn’t accept entity_ids. It would read them as string. You can, however, use templates there.
For those complex DPTs you’d have to pass a dict containing the right keys. Afaik, this isn’t documented anywhere, so you’d have to look it up in the code xknx/xknx/dpt/dpt_10.py at 60e0523513afbe773711bf9b2d37cc55aa7d467c · XKNX/xknx · GitHub
Or, as I already pointed out in your GH issue, just use a knx time entity.