Quantcast
Channel: Configuration - Home Assistant Community
Viewing all articles
Browse latest Browse all 106146

Human spoken time

$
0
0

I just wanted to share a little project I’ve been working on. I’ve got several automations that inform me, thought my Google speakers, when a certain event has happend. Whenever I call a time it will tell me that something happend at sixteen hours twelve minutes. I prefer a more human approach.

I’ve created a sensor:

- platform: template
  sensors:
    human_time:
      friendly_name: Human spoken time
		{% if (now().minute | float) == 0 %}
		  {{ now().strftime('%-I') }} uur

		{% elif (now().minute | float) >= 1 and (now().minute | float) <= 14 %}
		  {{ now().minute }} minuten over {{ now().strftime('%-I') }}

		{% elif (now().minute | float) == 15 %}
		  kwart over {{ now().strftime('%-I') }}

		{% elif (now().minute | float) >= 16 and (now().minute | float) <= 29 %}
		  {{ 30 - now().minute | int }} minuten voor half {{ now().strftime('%-I') | int + 1 }}

		{% elif (now().minute | float) == 30 %}
		  half {{ now().strftime('%-I') | int + 1 }}

		{% elif (now().minute | float) >= 31 and (now().minute | float) <= 44 %}
		  {{ now().minute | int - 30 }} minuten over half {{ now().strftime('%-I') | int + 1 }}

		{% elif (now().minute | float) == 45 %}
		  kwart voor {{ now().strftime('%-I') | int + 1 }}

		{% elif (now().minute | float) >= 46 and (now().minute | float) <=59 %}
		  {{ 60 - now().minute | int }} minuten voor {{ now().strftime('%-I') | int + 1 }}

		{% endif %}

And if I call:

service: tts.cloud_say
data:
  entity_id: media_player.woonkamer
  message: De tijd is nu {{ states('sensor.human_time') }}

then it’ll say the time in a more human way.

Next up is finding a way so I can use this template on a variety of times because it currently only says the current time.

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 106146

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>