Trouble Understanding Platforms

Hello,

In trying to troubleshoot why I can’t get the time_date integration working (which I still haven’t figured out) I stumbled across this post: Time sensor
That posts noted that there should only be one

  • sensor:

with all of the sensors listed under it. When I do so I get errors that I am missing a platform for each sensor. I am having trouble understanding what a platform is and what one I should use since I cannot find a list of them. Is it arbitrary in that I can put whatever I want as a platform for grouping purposes?

The integration page for time_date shows example of the correct format.

A “platform” equates to an “integration”, of which you will find many on the Integrations page of the HA site.

Note that since a lot of things have move to the GUI, you wouldn’t normally need to know that. The time_date integration is one that hasn’t, so you need to know this stuff.

Lastly - if you require assistance it’s best to post your yaml - making sure you use preformatted text tags (</> on the posting toolbar).

No. Not at all. The format is usually listed as an example on each integration’s page.

Post what you are trying here (correctly formatted) and we’ll try to help.

Also note where you are putting this config. Is it in configuration.yaml or are you using an !include for another file?

Thank you both for the quick reply.

# Example configuration.yaml entry
  - sensor:
     - platform: time_date
       display_options:
         - 'time'
         - 'date'
         - 'date_time'
         - 'date_time_utc'
         - 'date_time_iso'
         - 'time_date'
         - 'time_utc'
         - 'beat'

I copied and pasted above from the time and date integration page. I first tried adding it directly to my confirguation.yaml but no entities showed up. I then added it to my templates.yaml file where I keep all of my sensors. Which is connected to my confirguation.yaml via:

#Yaml File Locations
template: !include templates.yaml
sensor: !include sensor.yaml

The sensor,yaml is blank as when I moved all of my sensors there I started getting errors for missing platforms. I have a lot of sensors here is one of them (currently in my templates.yaml)

  - sensor:
    - name: Temperature in Celsius
      unique_id: temperature_in_celsius
      state: =
       {{ (((state_attr('weather.forecast_home', 'temperature') | float(0)) - 31) * (5/9)) | round(1) }} {{"°C"}} 

Check it again. Is there a dash before sensor?

As your configuration file has this (note: no dash before the sensor:):

You want this in sensor.yaml:

- platform: time_date
  display_options:
    - 'time'
    - 'date'
    - 'date_time'
    - 'date_time_utc'
    - 'date_time_iso'
    - 'time_date'
    - 'time_utc'
    - 'beat'

- platform: worldclock
  time_zone: Antarctica/Casey
  name: Casey

I added another sensor at the bottom to show you how more than one sensor platform goes in that file. Note that there is no “sensor:” in that file. It is already in your configuration.yaml file and points to this file to include. This is what that whole other topic you linked to was about.

This (below) however is part of the template integration. Not the sensor integration. Leave it in your templates.yaml file:

it does need the “- sensor:” (with the dash) as there can be many types of templates, e.g. buttons, boolean sensors, triggered sensors, etc…


I copied and pasted what you recommended to me into sensor. yaml and I still do not have any entities.

How do I know what sensors to keep in my template.yaml and which ones to move to my sensor. yaml?

You need to restart home assistant after adding that config for them to be loaded.

All the ones with - platform: ... go in your sensor.yaml file.

All the ones listed here go in your templates.yaml file.

I know. It is confusing that the sensor integration has sensor platforms and the template integration has template sensors. Legacy template sensors do go in the sensor.yaml file but don’t use them for new sensors. That was the way it used to be done.

If the word is hard up against the margin of configuration.yaml, like

sensor:

default_config:

template:

It is an integration.

I still don’t understand how to figure out what platform is needed when I make a sensor but I do understand now that I should probably leave my sensors as is since they work.

Restarting the whole system worked, I assumed that I could just restart the script. Thank you!

Now that I have the time date integration working I assumed that using the following line would result in a date time but it results in a string according to the template editor.

{{ as_datetime(states('sensor.to_do_list_preparations')) }}

what an I missing? For context I want to use this sensor to trigger an automation as a certain time. The sensor currently returns:

2024-01-09T21:19:00+00:00

You’re not missing anything, your template is fine and is returning a datetime object… the “Result type” isn’t 100% accurate.

Unless you need to apply offsets or do calculations, you likely don’t need a template and can use your sensor’s entity ID directly in a Time trigger.

I did that but then I got a weird situation where the automation was triggered but there was no trace (see pictures). I assumed that this had to do with the format of the sensor being an incorrect format but now that I think about it, it wouldn’t have triggered in the first place if that was the case. Is this a bug?