Create a sensor from another sensor's attribute

I don’t currently have an outside temperature/humidity sensor. I do have a fairly frequently updated weather service that provides me with what seem like accurate temperature and humidity values for my location. The temperature and humidity are in attributes of the weather sensor data.

I’ve found several posts telling me that the way to get this data out of an attribute is to create a new sensor with a state_attr() function which gets the value from the attribute. The sensor definition is to be put into a configuration file.

So, I have done the following and placed it in the configuration.yaml file. Then restarted HA.

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

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

# Text to speech
tts:
  - platform: google_translate

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


#SystemMonitor
# Example configuration.yaml entry with all entry types (delete/comment out as necessary)
sensor:
  - platform: systemmonitor
    resources:
      - type: disk_use_percent
        arg: /config
      - type: memory_use_percent

template:
  - sensor:
    - name: "LEV temperature"
      device_class: temperature
      state_class: measurement
      state: "{{ state_attr('weather.l_etang_la_ville', 'temperature') | float }}"
    - name: "LEV humidity"
      unit_of_measure: %
      state_class: measurement
      state: "{{ state_attr('weather.l_etang_la_ville', 'humidity') | float }}"

The SystmeMonitor section works fine - so I know I’m editing the right file.
I can tail the logfile (via docker) but I don’t see any log entries related to my new sensors, good or bad.
Am I putting this configuration in the right place? Is it well formatted? Am I missing something basic about how to work with HA configuration files? How can I double-check the attribute names are correct?

Sorry for all the questions, but I’m at the stage of using HA where I can see how much I don’t know!

Look at the example Template - Home Assistant (home-assistant.io)
Indentation is key

Is there a lint tool to check syntax? I have a 5 minute restart time, so iterating over the possibilities takes a while. And I haven’t found any error messages that would guide me to which line(s) in the file need attention.

The template sensor you can load without reboot, use the devtools > yaml …and load it from there
In this case it is two spaces that are missing

Don’t know, I use notepad++ and am aware of indentation. Possibly visual studio code can help ?

I’ve reduced it to this and I still get nada.
(Fixed the indent, took the space out of the name, quoted the name, reduced it to one sensor, checked the attribute name in DevTools, States).

Is there something foolproof (:sob:) that I can put in there to debug it?

Thanks for the Dev tool yaml reload tip; that saved a lot of time!

#SystemMonitor
# Example configuration.yaml entry with all entry types (delete/comment out as necessary)
sensor:
  - platform: systemmonitor
    resources:
      - type: disk_use_percent
        arg: /config
      - type: memory_use_percent

template:
  - sensor:
      - name: "hometemp"
        device_class: temperature
        state: "{{ state_attr('weather.l_etang_la_ville', 'temperature') | float }}"

Honestly, in the past I went your way too (a bit)…just knowing that if nothing showed …probably format :slight_smile:

Assuming you are having only one section that heads "template: "
With me your example runs fine, did you try this out in devtools > template?

{{ state_attr('weather.l_etang_la_ville', 'temperature') | float }}

It checks out in in the template checker.

There’s something else going on, but I don’t know where to look next. Thanks for your help so far; useful hints to build on!

Only option I see is then to increase logging to debug level and quickly but carefully examine, then turn it off

The short answer to all of this is: I don’t understand Docker.

I wasn’t editing the correct config/configuration.yaml file. I don’t know how this had previously worked, but now it’s the wrong file!

I’m back on track now.