HA 2023.8.1 it is not possible to create a template sensor

Hi.
I am new in HA.
I have read a lot of documentation to learn how to create a template sensor, but this task have been unsuccessful for me.

This is my configuration.yaml file:

# 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

sensor:
  - platform: template
    sensors:
      H_meter2:
        friendly_name: "H meter 2"
        value_template: "{{ states('sensor.ltst_2_as_humidity') | float(0) }}"

template:
  - sensor:
    - name: "T meter 2"
      state_class: "measurement"
      unit_of_measurement: "W"
      state: "{{ states('sensor.ltst_2_as_temperature') | float(0) }}"

The template sensors in my configuration.yaml files were tested Ok in template tool, but they do not even show up in the Development Tool ā†’ States.

After restarting HA, no errors appear related to template sensors.

I appreciate any help

template:
  - sensor:
      - name: whatever
        state: "{{ states('sensor.ltst_2_as_temperature','state') | float(0) }}"

Indentation on name and format of template. The first example is, as far as I remember, the legacy method.

Nope. As long as you are consistent within each block the amount of indentation is not important. e.g. all these are valid:

dictionary:
  - key_1: value_1
  - key_2: value_2
  - key_3: value_3
dictionary:
- key_1: value_1
- key_2: value_2
- key_3: value_3
dictionary:
      - key_1: value_1
      - key_2: value_2
      - key_3: value_3

My guess is that they did not restart home assistant after creating the template sensors. This has to be done the first time a yaml integration s used. After that you can use the reload option (if there is one available).

Wait, what? Iā€™m a doofus. I also didnā€™t realize you donā€™t need comma ā€˜stateā€™ inside of the parenthesisā€¦

yaml is confusing. Why is indentation in the yaml for the UI so picky then?

You donā€™t.

I donā€™t have an answer to your question, but since you are new to Home Assistant, just to be clear on this: in your example you are mixing the legacy and the modern format of template sensors. The first sensor ā€œH meter 2ā€ is legacy and the second sensor ā€œT meter 2ā€ is modern.

It obviously is confusing to find a lot of example code in both formats, so keep an eye on that.

Both formats are (as far as I know) identical in functionality, but it might be that in an unforeseen future the legacy format will be abrogated (and it already is no longer recommended by the HA makers). So when you are starting from scratch it is best to stick with one format, preferably the modern format.

Not quite. The legacy format does not support a state_class.

There are no plans to drop the legacy format but it will not be receiving new features. Thus it is best to use the new format for new sensors.

1 Like

Thanks! I should have known that.

OP, always check your log first.
If you did but didnā€™t see an error (unlikely), mention it.

Machine tend to be far better than humans at detecting syntax errors :smiley:

Hi @tom_l , thanks for your reply.

I confirm i tested the configuration.yaml file as shown above, and next I applied Development Tools ->YAML ā†’ Restart

Also, I tried 2 more cases with only one of the declared sensors (one only legacy, another one only modern)

In all the cases, Settings ā†’ System ā†’ Logs did not show error for those sensors.
After Restart, none of the sensors showed up in Development Tools ā†’ STATES.

It looks like that HA is not rendering the sensors in the configuraion.yaml file.

Any other idea ???

Hi @thusassistint , thanks for your reply.

I confirm i tested the configuration.yaml file as shown above, and next I applied Development Tools ->YAML ā†’ Restart

Also, I tried 2 more cases with only one of the declared sensors (one only legacy, another one only modern)

In all the cases, Settings ->.System ā†’ Logs did not show error for those sensors.
After Restart, none of the sensors showed up in Development Tools ā†’ STATES.

It looks like that HA is not rendering the sensors in the configuraion.yaml file.

Any other idea ???

Hi @koying, thanks for your reply.

I confirm I checked the log and I did not see any error related to sensors in configurqtion.yaml file.

This is the log for one of the cases i tried:

2023-08-24 13:39:01.046 WARNING (SyncWorker_0) [homeassistant.loader] We found a custom integration hacs which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant
2023-08-24 13:39:01.048 WARNING (SyncWorker_0) [homeassistant.loader] We found a custom integration tuya_local which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant
2023-08-24 13:39:01.050 WARNING (SyncWorker_0) [homeassistant.loader] We found a custom integration hass_cozylife_local_pull which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant
2023-08-24 13:39:08.476 WARNING (MainThread) [homeassistant.util.async_] Detected blocking call to sleep inside the event loop. This is causing stability issues. Please report issue to the custom integration author for tuya_local doing blocking calls at custom_components/tuya_local/device.py, line 76: self._api = tinytuya.Device(dev_id, address, local_key)
2023-08-24 13:39:09.421 WARNING (MainThread) [homeassistant.util.async_] Detected blocking call to sleep inside the event loop. This is causing stability issues. Please report issue to the custom integration author for tuya_local doing blocking calls at custom_components/tuya_local/device.py, line 76: self._api = tinytuya.Device(dev_id, address, local_key)
2023-08-24 13:39:13.473 WARNING (MainThread) [homeassistant.util.async_] Detected blocking call to sleep inside the event loop. This is causing stability issues. Please report issue to the custom integration author for tuya_local doing blocking calls at custom_components/tuya_local/device.py, line 76: self._api = tinytuya.Device(dev_id, address, local_key)
2023-08-24 13:39:13.712 WARNING (MainThread) [homeassistant.util.async_] Detected blocking call to sleep inside the event loop. This is causing stability issues. Please report issue to the custom integration author for tuya_local doing blocking calls at custom_components/tuya_local/device.py, line 76: self._api = tinytuya.Device(dev_id, address, local_key)
2023-08-24 13:39:18.808 WARNING (MainThread) [homeassistant.util.async_] Detected blocking call to sleep inside the event loop. This is causing stability issues. Please report issue to the custom integration author for tuya_local doing blocking calls at custom_components/tuya_local/device.py, line 76: self._api = tinytuya.Device(dev_id, address, local_key)
2023-08-24 13:39:22.149 WARNING (MainThread) [homeassistant.util.async_] Detected blocking call to sleep inside the event loop. This is causing stability issues. Please report issue to the custom integration author for tuya_local doing blocking calls at custom_components/tuya_local/device.py, line 76: self._api = tinytuya.Device(dev_id, address, local_key)
2023-08-24 13:39:23.765 WARNING (MainThread) [homeassistant.util.async_] Detected blocking call to sleep inside the event loop. This is causing stability issues. Please report issue to the custom integration author for tuya_local doing blocking calls at custom_components/tuya_local/device.py, line 76: self._api = tinytuya.Device(dev_id, address, local_key)
2023-08-24 13:39:26.222 WARNING (MainThread) [homeassistant.util.async_] Detected blocking call to sleep inside the event loop. This is causing stability issues. Please report issue to the custom integration author for tuya_local doing blocking calls at custom_components/tuya_local/device.py, line 76: self._api = tinytuya.Device(dev_id, address, local_key)
2023-08-24 13:39:26.637 WARNING (MainThread) [homeassistant.setup] Setup of input_number is taking over 10 seconds.
2023-08-24 13:39:26.638 WARNING (MainThread) [homeassistant.setup] Setup of input_select is taking over 10 seconds.
2023-08-24 13:39:26.639 WARNING (MainThread) [homeassistant.setup] Setup of input_text is taking over 10 seconds.
2023-08-24 13:39:26.640 WARNING (MainThread) [homeassistant.setup] Setup of zone is taking over 10 seconds.
2023-08-24 13:39:26.641 WARNING (MainThread) [homeassistant.setup] Setup of input_button is taking over 10 seconds.
2023-08-24 13:39:26.642 WARNING (MainThread) [homeassistant.setup] Setup of input_boolean is taking over 10 seconds.
2023-08-24 13:39:26.643 WARNING (MainThread) [homeassistant.setup] Setup of input_datetime is taking over 10 seconds.
2023-08-24 13:39:26.644 WARNING (MainThread) [homeassistant.setup] Setup of schedule is taking over 10 seconds.
2023-08-24 13:39:26.645 WARNING (MainThread) [homeassistant.setup] Setup of media_source is taking over 10 seconds.
2023-08-24 13:39:26.646 WARNING (MainThread) [homeassistant.setup] Setup of system_health is taking over 10 seconds.
2023-08-24 13:39:26.647 WARNING (MainThread) [homeassistant.setup] Setup of logbook is taking over 10 seconds.
2023-08-24 13:39:26.648 WARNING (MainThread) [homeassistant.setup] Setup of automation is taking over 10 seconds.
2023-08-24 13:39:26.649 WARNING (MainThread) [homeassistant.setup] Setup of application_credentials is taking over 10 seconds.

What happen if you look for the entities, i.e

I confirm I checked, and sensor did not show up as well

Ok, this is spooky :ghost:

What is your installation method, and how do you edit configuration.yaml?

I installed Home Assistance Container in a Ubuntu machine.
I use VSCODE in my PC with Windows 10.
VSCODE works via SSH to the Ubuntu machine.

Could you show your docker-compose.yml or docker run command, please

docker-compose.yaml

version: '3.0'

services:
  portainer:
    container_name: portainer
    image: portainer/portainer-ce
    restart: always
    ports:
      - "9000:9000/tcp"
    environment:
      - TZ=Asia/Manila
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - /opt/portainer:/data
  homeassistant:
    container_name: homeassistant
    image: "ghcr.io/home-assistant/home-assistant:stable"
    volumes:
      - /opt/homeassistance/config:/config
      - /etc/localtime:/etc/localtime:ro
    restart: unless-stopped
    privileged: true
    network_mode: host

And you are editing /opt/homeassistance/config/configuration.yaml, right?
If so, Iā€™m cluelessā€¦

1 Like

It looks like you have found my mistake.
Give me some minutes. I am checking