HA – good to know & snippets


Format date/time
With the now().strftime(‘XXX’), you can output the current date/time, in a certain format.
Replacing the XXX with a combination of “Format”, allows you to get a timestamp in the format your prefer. You can add multiple format tags, and also include other characters.

FormatDescription
%aName of day, first 3 characters
%AName of day, in full
%dNumber of day (formatted in 2 digits)
%BName of month, in full
%mNumber of month (formatted in 2 digits)
%YNumber of year (formatted in 4 digits)
%HHour (24-hours format)
%IHour (12-hours format)
%pAM / PM
%MMinute (formatted in 2 digits)
%SSecond (formatted in 2 digits)
%UWeeknumber (formatted in 2 digits)
%jDay count (formatted in 3 digits)

Counters
You can use the following lines in scripting / automation, or simply put it in the templates editor,
under development.

DescriptionCommand
Lights{{ states.light | count }}
Switches{{ states.switch | count }}
Binary sensors{{ states.binary_sensor | count }}
Sensors{{ states.sensor | count }}
Automations{{ states.automation | count }}
Entities{{ states | count }}
Trackers{{ states.device_tracker | count }}
Climate{{ states.climate | count }}
Media-players{{ states.media_player | count }}
Cameras{{ states.camera | count }}
Persons{{ states.person | count }}
Helpers-boolean{{ states.input_boolean | count }}
Helpers-select{{ states.input_select | count }}
Helpers-text{{ states.input_text | count }}
Helpers-counter{{ states.counter | count }}

Multiple spaces
Sometimes you need more then one space-character.
Due to the nature of HTML, this gets most of the time, reduced to one character.
However, there is a simple solution for it:
*Press and hold <ctrl> and <shift> together.
*next, type U 0 0 A 0
*after this, press <space> and let go the <ctrl> and <shift> key.
*You will then have a space that you can copy/paste, and you can put it multiple times on a line.
*Note that with some fonts, this gives a “visible” character 🙁

This entry was posted in Blog, Home Assistant, Tutorials. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *