Configuring mqtt sensors trouble .. what am i doing wrong?

Trying to understand how to go about this :joy: I want to set up 2 sensors from a mqtt topic… I currently have this in my configuration.yaml

mqtt:
  sensor:
    name: "Household Electricity Usage"
    icon: mdi:transmission-tower
    state_topic: "event/metering/summation/minute"
    unit_of_measurement: "kWh"
    # the Energy Bridge returns "Watt-minutes" every minute in the "value"; convert it to kilowatt-hours
    value_template: "{{ value_json.value | float / 60000 }}"
    # the "time" in the message is a Unix-like timestamp (in milliseconds) of the start of the last reading
    last_reset_value_template: "{{ now().fromtimestamp(value_json.time / 1000).replace(tzinfo=now().tzinfo) }}"
    device_class: energy
    state_class: total

but there is second value I want to get into HASS … not just ‘event/metering/summation’ but also ‘event/metering/instantaneous_demand’

so i was looking into creating a sensors.yaml file but this is where I’m struggling … no matter what combo of entries I put in this file I get errors :frowning_face:

I think something like this should work… I should be able to add a second sensor… but i don’t understand this error

all help appreciated!

mqtt:
  sensor:
  - name: "Household Electricity Usage"
    icon: mdi:transmission-tower
    state_topic: "event/metering/summation/minute"
    unit_of_measurement: "kWh"
    # the Energy Bridge returns "Watt-minutes" every minute in the "value"; convert it to kilowatt-hours
    value_template: "{{ value_json.value | float / 60000 }}"
    # the "time" in the message is a Unix-like timestamp (in milliseconds) of the start of the last reading
    last_reset_value_template: "{{ now().fromtimestamp(value_json.time / 1000).replace(tzinfo=now().tzinfo) }}"
    device_class: energy
    state_class: total
  - name: "second sensor"
    icon: mdi:transmission-tower
    state_topic: "event/metering/instantaneous_demand"
    unit_of_measurement: "kWh"
    # the Energy Bridge returns "Watt-minutes" every minute in the "value"; convert it to kilowatt-hours
    value_template: "{{ value_json.value | float / 60000 }}"
    # the "time" in the message is a Unix-like timestamp (in milliseconds) of the start of the last reading
    last_reset_value_template: "{{ now().fromtimestamp(value_json.time / 1000).replace(tzinfo=now().tzinfo) }}"
    device_class: energy
    state_class: total

Thanks for responding! Tried it - but I see this now :thinking:

I tried one more variation by adding platform

mqtt:
  sensor:
    - name: "Household Electricity Usage"
      icon: mdi:transmission-tower
      state_topic: "event/metering/summation/minute"
      unit_of_measurement: "kWh"
      # the Energy Bridge returns "Watt-minutes" every minute in the "value"; convert it to kilowatt-hours
      value_template: "{{ value_json.value | float / 60000 }}"
      # the "time" in the message is a Unix-like timestamp (in milliseconds) of the start of the last reading
      last_reset_value_template: "{{ now().fromtimestamp(value_json.time / 1000).replace(tzinfo=now().tzinfo) }}"
      device_class: energy
      state_class: total
    - name: "second sensor"
      icon: mdi:transmission-tower
      state_topic: "event/metering/instantaneous_demand"
      unit_of_measurement: "kWh"
      # the Energy Bridge returns "Watt-minutes" every minute in the "value"; convert it to kilowatt-hours
      value_template: "{{ value_json.value | float / 60000 }}"
      # the "time" in the message is a Unix-like timestamp (in milliseconds) of the start of the last reading
      last_reset_value_template: "{{ now().fromtimestamp(value_json.time / 1000).replace(tzinfo=now().tzinfo) }}"
      device_class: energy
      state_class: total

Thanks this is the latest error

Are you using vscode ? It is out-of-date on mqtt.

I am … when you say out of date?! it’s just an editor … ah wait you mean the prompts … guess I can ignore them

I went a slightly different route… created a sensors folder and created a entry in 2 files for each mqtt topic like this

and added this in the configuration.yaml

ignoring the warning … I can reload the yaml but the 2 entities i was hoping would show up don’t :slightly_frowning_face:

Won’t work. MQTT is not a platform anymore.

@francisp just want to say thanks for all your pointers… I finally figured it out. Learnt the way to set up a directory with individual sensor configurations and how the hierachy works when defining in the configuration.yaml

More importantly… 2 other things. The plugins aren’t always reliable for configuration you really have to go back to the documentation of the current version to confirm you have it right. Second don’t copy/paste stuff from the www … more than likely it’s for an older version of HASS so doesn’t work quite the same anymore … :joy: