Today is my first day with Home Assistant (installed on Synology as Docker image).
I would like to show the value of the sensor swiss_public_transport on my dashboard in an Entities Card. The default output is a datetime value, e.g.: 2023-12-27T20:36:00+0100, but I would like to have it in the format %H:%M.
What I did so far is to create the sensor in Configuration.yaml as described on the integration details page:
sensor:
- platform: swiss_public_transport
name: TrainWinterthurZurich
from: Winterthur
to: Zurich
To show the formatted value, I thought I’d have to create a template:
I did some more try and error and finally found the correct solution, apparently I did some mistakes in the yaml format and mixed legacy with modern style.
Welcome!
Quick extra tip, I like to have the availability attribute linked to the sensor(s) being processed for any integration that calls a third party that could easily fail (like retrieving values from a website/API). It will avoid you the hassle of figuring out potential errors down the road (API goes down for maintenance, etc).
You can also check the validity of the attribute itself, just in case.
However, I agree with CO_4X4, if it’s just to display a plain, formatted value somewhere (dashboard, notification, etc), you can do it “in place” (markdown card, templated value, etc), instead of creating a “duplicate” sensor. It doesn’t seem like much at the beginning, but if you duplicate sensors for every type of formatting you could want, for every sensor you have, you quickly could end up with hundreds of template sensors… and a headache.
My rule is, if it doesn’t need history tracking, and isn’t involving multiple sensors, then a template sensor is not needed.