Adding MQTT topic (a sensor) to HA dashboard - not working

I want to add one of my sensors that comes into NodeRed (I publish its data to a MQTT topic) onto a HA dashboard.

configuration.yaml includes the following:

sensor:
  - platform: mqtt
    name: "GenBatt"
    state_topic: "myenergi/zappi/power"
    unit_of_measurement: "W"
    value_template: "{{ value_json['0_genbatt'] }}"

Reading on the web, I should be able to see this entity under Development Tools > States. It isn’t there. I’m assuming once it appears there, then the rest should be straight forward to add to a dashboard.

I’ve used the Developer Tools > Template utility to test my Json payload and that works.

{%
set my_test_json =
  {
    "0_power":-5,"0_zappi":0,"0_genbatt":371,"0_house":365
  }
%}

The energy is {{ my_test_json['0_genbatt'] }}
The energy is 371

What am I missing? No errors being reported on HA - so believe the config file is correct.

Thank you!

does not work anymore, new syntax is

# Example configuration.yaml entry
mqtt:
  - sensor:
      state_topic: "myenergi/zappi/power"
2 Likes

Thank you. I’m sure I tried that at one time but was getting an error. I copied the example as referenced and updated and now working. Thank you @francisp for the prompt response!

Config is now:

mqtt:
  - sensor:
      name: "GenBatt"
      state_topic: "myenergi/zappi/power"
      unit_of_measurement: "W"
      value_template: "{{ value_json['0_genbatt'] }}"