I have gone from OZE to ZWave JS fra OZW, and the feedback of my thermostats have changed to break the associated automations. I have been using this to send the feedback over MQTT from Hass to Event Ghost (which is sort of the “backend” of my system):
action:
data_template:
payload_template: "{{states('climate.termostat_'+trigger.from_state.attributes.friendly_name.split(' ')[1])}},{{state_attr('climate.termostat_'+trigger.from_state.attributes.friendly_name.split(' ')[1], 'node_id')}},{{state_attr('climate.termostat_'+trigger.from_state.attributes.friendly_name.split(' ')[1], 'current_temperature')}},{{trigger.from_state.attributes.friendly_name.split(' ')[1]}},{{state_attr('climate.termostat_'+trigger.from_state.attributes.friendly_name.split(' ')[1], 'temperature')}}"
topic: eg/Gulvtemperatur
service: mqtt.publish
condition: []
id: '110343257'
trigger:
- platform: state
entity_id:
- sensor.termostat_1_temperature
- sensor.termostat_2_temperature
- sensor.termostat_3_temperature
The problem is that Friendly name has changed with a colon directly after the name, so instead of Termostat 1 I get Termostat 1: with a colon. So where trigger.from_state.attributes.friendly_name.split(' ')[1]
gave me the number as 1, 2 or 3, I now get 1:, 2: and 3:
How can I best remove that colon and get to the numbers only in that split? Of course it would be even better to first set a variable in the automation that is the number and then use that in the rest of the payload template, but I’m not sure that’s possible.
in a momemt of hybris and panic I tried this: trigger.from_state.attributes.entity_id.split('_')[1]
, but that didn’t work out at all:
Gulvtemperatur med modus: Error executing script. Invalid data for call_service at pos 1: string value is None for dictionary value @ data[‘payload_template’]
Gulvtemperatur med modus: Error executing script. Error for call_service at pos 1: Error rendering data template: UndefinedError: ‘mappingproxy object’ has no attribute ‘entity_id’
Can somebody please put me out of my misery?