Templates returning "null"

Im my configuration.yaml I have:

# Loads default set of integrations. Do not remove.

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

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

    - 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?


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