Feedback from thermostate changed with ZWave JS - how do I split twice or remove a colon?

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?

If trigger.from_state.attributes.friendly_name.split(' ')[1] gives you 1: then I think trigger.from_state.attributes.friendly_name.split(' ')[1].split(":")[0] should give you just 1.

Why don’t you just change the friendly name of the entities?

2 Likes

@septillion Afraid not. That gives me “Termostat 1”, so everything before the “new” colon. Which is why I probably need to double split, or delete the last character.

@freshcoast Because whatever name I choose, the number will be followed by a colon. And a space added after then name is just deleted by Hass.

I think you do something wrong. Because if the original gives back 1: it’s simply not possible to get Termostat 1 back now. Didn’t you copy it and missed the fact there is now a double split? :wink: That would indeed give you the outcome you have now.

No, that’s not possible. :laughing: The full friendly name is “Termostat 1”. So a space between the Termostat and the 1. Which is what it splits on. If I had used [0] for the split, it would have given the part before the space, which is Termostat. And the origial gave me only 1 without a colon after. But after the change in ZWave, from OZW to ZWave JS, I get an extra : (colon) added to the friendly name somewhere in the integration, either from ZWave JS or from the actual integration in Hass.

The suggestion was to split on the colon, but that of course gives me everything before the colon, and that doesn’t help. I need only the 1 without a colon or anything else.

The suggestion was to ALSO split on the semicolon :wink: Aka, don’t mess with the first split :slight_smile:

Original:
trigger.from_state.attributes.friendly_name.split(' ')[1]

My suggestion:
trigger.from_state.attributes.friendly_name.split(' ')[1].split(":")[0]

What you probably made of it:
trigger.from_state.attributes.friendly_name.split(":")[0]

Oh, sorry! I apologize! Somehow my brain didn’t register that second split! :grimacing: I’ll try to restart my brain… I had to make one change, replace the double quotes with single quotes, and then it worked! Thanks a lot, and sorry for my morning brain! :flushed: