Template sensor using Sun integration (1st Dashboard customization)

Hi,
without external sensors available I tried some approaches to use/change the Dashboard to use integrations with no further external hardware required.
Beside the Battery status of our mobiles (via Owntracks App), I copied the code from:

sensor:
  - platform: template
    sensors:
      solar_angle:
        friendly_name: "Sun angle"
        unit_of_measurement: 'degrees'
        value_template: "{{ state_attr('sun.sun', 'elevation') }}"
      sunrise:
        value_template: "{{ state_attr('sun.sun', 'next_rising') }}"

But contrary to the Battery Status entities I do see if I want to add a sensor to the Dashboard, there is no entity available to be added related to the SUN Integration.

The SUN integration is shown on the top of the Dasboard in the red circle and I can open and see the values for sunset etc., but the Tempate Sensor code in my configuration.yaml doesn’t seem to have any influence.

Any idea, what might be wrong in teh above code?

Best regards,
Jörg

My complete config file is:


# Configure a default setup of Home Assistant (frontend, api, etc)
default_config:

# Uncomment this if you are using SSL/TLS, running in Docker container, etc.
# http:
#   base_url: example.duckdns.org:8123

# Text to speech
tts:
  - platform: google_translate

group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml

media_player:
  - platform: yamaha_musiccast
    host: 192.168.1.84
    port: 5005
 
 # Example configuration.yaml entry
sensor:
  - platform: template
    sensors:
      solar_angle:
        friendly_name: "Sun angle"
        unit_of_measurement: 'degrees'
        value_template: "{{ state_attr('sun.sun', 'elevation') }}"
      sunrise:
        value_template: "{{ state_attr('sun.sun', 'next_rising') }}"
        
 # mqtt:
   # broker: 192.168.1.70
     # port: 1883
     # Username: sensor
     # Password: mqtt1234
    
sensor:
  - platform: mqtt
    state_topic: "owntracks/Sensor/lg"
    name: "Batterie_joerg"
    unit_of_measurement: "%"
    value_template: '{{ value_json.batt }}'
    device_class: battery
  - platform: mqtt
    state_topic: "owntracks/Sensor/hw"
    name: "Batterie_ja"
    unit_of_measurement: "%"
    value_template: '{{ value_json.batt }}'
    device_class: battery

You have the sensor key listed twice in your configuration. You need to group all sensors under the one sensor: key. (Specifically, remove the line containing sensor: that is right above the line containing - platform: mqtt.)

Perfect Thanks!

1 Like