Templates returning "null"

Im my configuration.yaml I have:

# Loads default set of integrations. Do not remove.
default_config:

# Load frontend themes from the themes folder
frontend:
  themes: !include_dir_merge_named themes

automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml

mqtt:
  sensor:
    - name: Importing
      state_topic: "Home/Kaifa"
      value_template: "{{ value_json.importing_power | float / 1000 }}"
      unit_of_measurement: "kWh"
      icon: mdi:transmission-tower

I can get the sensor data with no problem.

On Developer Tools tab I am using:

{{ state_attr('sensor.importing', 'Importing') }}

However, the template returns “null”.

What am I missing? Why I can’t get the sensor’s value?

Thanks!

Because you’re asking for the non-existent Importing attribute of the sensor, whereas you want its state. Use:

{{ states('sensor.importing') }}

Then read this to avoid future mistakes:

1 Like

I have tried it before and did not work…
I guess I made a change on the config file and did not restart the MQTT config.
Sorry for my mistake and big thanks for you very quick help.

1 Like