Problem sensor template

Hi all,
I have sensor.mqttgarage that is a string with the value of many sensor:

sensor:
    - platform: mqtt
      name: "MQTTgarage"
      state_topic: "home-assistant/sensor03/messaggio"
      qos: 0

image

Now, I need to create many single sensor, like this:

sensor:
    - platform: template
      sensors:
        frequency:
          value_template: "{{ states('sensor.mqttgarage').split(',')[8] | float }}"
          unit_of_measurement: "Hz"

But HA doesn’t show the sensor.frequency…

Where is the error?

Thanks

indicies start at 0, not 1. So your first item is 0 and your last item is 7. You’re using 8. That’s why it’s failing. Also, you don’t need the word float, that will only hurt you in this case.

          value_template: "{{ states('sensor.mqttgarage').split(',')[7] }}"

thanks for you reply…
I know, I have 9 sensors, so from 0 to 8…
I tried also without float but the same problem…

Also, as a sidebar, you can make template sensors without the mqttgarage sensor:

template:
- trigger:
  - platform: mqtt
    topic: home-assistant/sensor03/messaggio
  sensor:
  - name: First item
    state: "{{ value.split(',')[0] }}"
  - name: Second item
    state: "{{ value.split(',')[1] }}"
    ... ETC...
  - name: Frequency (Last Item)
    state: "{{ value.split(',')[-1] }}"
1 Like

Then your topic is wrong or you didn’t reload templates after adding the template. Or if you’re using the new template integration, you didn’t restart home assistant.

I tried this, but sensor.frequency is unavailable

template:
- trigger:
  - platform: mqtt
    topic: home-assistant/sensor03/messaggio
  sensor:
  - name: frequency
    state: "{{ value.split(',')[8] }}"
    unit_of_measurement: "Hz"

oops, it should be

template:
- trigger:
  - platform: mqtt
    topic: home-assistant/sensor03/messaggio
  sensor:
  - name: frequency
    state: "{{ trigger.payload.split(',')[8] }}"
    unit_of_measurement: "Hz"

many thanks, if I need to scale the value, for example /1000?ù
like this doesn’t work:
state: “{{ ( trigger.payload.split(‘,’)[1] / 1000 ) | float | round (1) }}”

float has to be applied before you divide

many thanks!