I am finding it difficult to resolve this issue and I would be grateful for any help. I have two raspberry pi 3’s running home assistant. Hassbian1 is the primary controller and hassbian2 is in MQTT communication with hassbian1.
To subscribe to the times for a pump to start from hassbian2 to hassbian1 I have the following automation in hassbian1:
- alias: MQTT subscribe input_datetime command
trigger:
- platform: mqtt
topic: 'hassbian2/input_datetime/pool_start_time/state'
- platform: mqtt
topic: 'hassbian2/input_datetime/pool_stop_time/state'
action:
- service_template: "input_datetime.set_datetime"
entity_id: "input_datetime.{{trigger.topic.split('/')[2]}}"
data_template:
time: "{{trigger.payload}}"
This comes out as “Valid YAML” in yamllint.com. But it produces the following error:
hassbian1 hass[2556]: 2019-10-03 22:14:12 ERROR (MainThread) [homeassistant.config] Invalid config for [automation]: not a valid value for dictionary value @ data['action'][0]['entity_id']. Got "input_datetime.{{trigger.topic.split('/')[2]}}". (See /home/homeassistant/.homeassistant/automations.yaml, line 125). Please check the docs at https://home-assistant.io/components/automation/
If I change the line:
entity_id: "input_datetime.{{trigger.topic.split('/')[2]}}"
to:
entity_id: "input_datetime.pool_start_time"
this works fine, but of course only updates the pool_start_time, not the pool_end_time.
I have used {{trigger.topic.split(’/’)[2]}} in a different context in other automations:
- alias: MQTT subscribe input_boolean command
initial_state: 'true'
trigger:
- platform: mqtt
topic: 'hassbian2/input_boolean/automated_pool_pump/set'
- platform: mqtt
topic: 'hassbian2/input_boolean/turn_on_pool_for_specified_duration/set'
- platform: mqtt
topic: 'hassbian2/input_boolean/start_pool_set_times/set'
action:
service_template: "input_boolean.turn_{{trigger.payload | lower}}"
data_template:
entity_id: "input_boolean.{{trigger.topic.split('/')[2]}}"
and this works fine.
All advice gratefully received.