I have a datetime time entity that I am looking to push to MQTT, and also update from another MQTT topic if the connected system wants to push a value to HA. I can’t seem to set two datetime entities using a split from the source message. This is my configuration as it stands:
input_datetime:
pethub_curfew_start:
name: Curfew Start
has_time: true
icon: mdi:clock-start
pethub_curfew_end:
name: Curfew End
has_time: true
icon: mdi:clock-end
And in Automations I have:
- id: curfewtomqtt
alias: "Pet Hub Curfew to MQTT"
trigger:
platform: state
entity_id:
- input_datetime.pethub_curfew_start
- input_datetime.pethub_curfew_end
action:
- service: mqtt.publish
data:
topic: pethub/curfewtest
payload_template: "{{ states('input_datetime.pethub_curfew_start')[0:5] }}-{{ states('input_datetime.pethub_curfew_end')[0:5] }}"
- id: mqtttocurfew
alias: "MQTT to Pet Hub Curfew"
trigger:
- platform: mqtt
topic: 'pethub/curfewtestset'
action:
- service: input_datetime.set_datetime
target:
entity_id: input_datetime.pethub_curfew_start
data:
time: "{{ trigger.payload.split('-')[0] }}"
- delay: '00:00:01'
- service: input_datetime.set_datetime
target:
entity_id: input_datetime.pethub_curfew_end
data:
time: "{{ trigger.payload.split('-')[1] }}"
The idea is I have a MQTT topic that holds HH:MM-HH:MM
for the start / end time, and when either value is changed in HA it publishes to the topic, and vice versa if I publish to MQTT it updates the datetime entities.
The only way I have managed to get this working is to add a delay: '00:00:01'
and I was wondering if there was a better / cleaner way.