Hello,
I’m planning to use an Ulanzi clock to display the time so that my son can understand whether it’s time to go to sleep or not, without having to read a digital clock.
I’m a beginner, but I wanted to start something just to have a base. For the moment, my aim is to display an icon for sunrise and sunset, for day and night (which I’ve managed to do). Then, next to it, display the digital time (which I couldn’t figure out how to do, so I had fun putting in my temperature sensor, which isn’t really very useful in my case).
Here’s my code, I’m open to criticism in order to improve it, or if there are better practices to implement. I’d like to know if I can display the time instead of my temperature, or if I have to use the integrated app.
alias: Afficher icône en fonction du cycle jours nuit
description: Afficher icône en fonction du cycle jours nuit
trigger:
- platform: state
entity_id: sensor.cycle_jour_nuit
- platform: state
entity_id: sensor.exterieur_temperature
action:
- choose:
- conditions:
- condition: state
entity_id: sensor.cycle_jour_nuit
state: Jour
sequence:
- data:
topic: awtrix_45a8e0/custom/1
qos: 0
retain: false
payload: >-
{"icon": 11201, "text": "{{
states('sensor.exterieur_temperature') }}°", "color": "{{
'D977DF' if (states('sensor.exterieur_temperature') | int) <=
-12 else
'9545BC' if (states('sensor.exterieur_temperature') | int) <= -6 else
'4B379C' if (states('sensor.exterieur_temperature') | int) <= -1 else
'FEC4FF' if (states('sensor.exterieur_temperature') | int) <= 0 else
'31B8DB' if (states('sensor.exterieur_temperature') | int) <= 4 else
'31DB8B' if (states('sensor.exterieur_temperature') | int) <= 10 else
'6ED228' if (states('sensor.exterieur_temperature') | int) <= 15 else
'FFFF28' if (states('sensor.exterieur_temperature') | int) <= 21 else
'F87E27' if (states('sensor.exterieur_temperature') | int) <= 27 else
'CF3927' if (states('sensor.exterieur_temperature') | int) <= 32 else
'A12527' }}"}
action: mqtt.publish
- conditions:
- condition: state
entity_id: sensor.cycle_jour_nuit
state: Couché du soleil
sequence:
- data:
topic: awtrix_45a8e0/custom/1
qos: 0
retain: false
payload: >-
{"icon": 2859, "text": "{{
states('sensor.exterieur_temperature') }}°", "color": "{{
'D977DF' if (states('sensor.exterieur_temperature') | int) <=
-12 else
'9545BC' if (states('sensor.exterieur_temperature') | int) <= -6 else
'4B379C' if (states('sensor.exterieur_temperature') | int) <= -1 else
'FEC4FF' if (states('sensor.exterieur_temperature') | int) <= 0 else
'31B8DB' if (states('sensor.exterieur_temperature') | int) <= 4 else
'31DB8B' if (states('sensor.exterieur_temperature') | int) <= 10 else
'6ED228' if (states('sensor.exterieur_temperature') | int) <= 15 else
'FFFF28' if (states('sensor.exterieur_temperature') | int) <= 21 else
'F87E27' if (states('sensor.exterieur_temperature') | int) <= 27 else
'CF3927' if (states('sensor.exterieur_temperature') | int) <= 32 else
'A12527' }}"}
action: mqtt.publish
- conditions:
- condition: state
entity_id: sensor.cycle_jour_nuit
state: Nuit
sequence:
- data:
topic: awtrix_45a8e0/custom/1
qos: 0
retain: false
payload: >-
{"icon": 13345, "text": "{{
states('sensor.exterieur_temperature') }}°", "color": "{{
'D977DF' if (states('sensor.exterieur_temperature') | int) <=
-12 else
'9545BC' if (states('sensor.exterieur_temperature') | int) <= -6 else
'4B379C' if (states('sensor.exterieur_temperature') | int) <= -1 else
'FEC4FF' if (states('sensor.exterieur_temperature') | int) <= 0 else
'31B8DB' if (states('sensor.exterieur_temperature') | int) <= 4 else
'31DB8B' if (states('sensor.exterieur_temperature') | int) <= 10 else
'6ED228' if (states('sensor.exterieur_temperature') | int) <= 15 else
'FFFF28' if (states('sensor.exterieur_temperature') | int) <= 21 else
'F87E27' if (states('sensor.exterieur_temperature') | int) <= 27 else
'CF3927' if (states('sensor.exterieur_temperature') | int) <= 32 else
'A12527' }}"}
action: mqtt.publish
- conditions:
- condition: state
entity_id: sensor.cycle_jour_nuit
state: Levé du soleil
sequence:
- data:
topic: awtrix_45a8e0/custom/1
qos: 0
retain: false
payload: >-
{"icon": 2860, "text": "{{
states('sensor.exterieur_temperature') }}°", "color": "{{
'D977DF' if (states('sensor.exterieur_temperature') | int) <=
-12 else
'9545BC' if (states('sensor.exterieur_temperature') | int) <= -6 else
'4B379C' if (states('sensor.exterieur_temperature') | int) <= -1 else
'FEC4FF' if (states('sensor.exterieur_temperature') | int) <= 0 else
'31B8DB' if (states('sensor.exterieur_temperature') | int) <= 4 else
'31DB8B' if (states('sensor.exterieur_temperature') | int) <= 10 else
'6ED228' if (states('sensor.exterieur_temperature') | int) <= 15 else
'FFFF28' if (states('sensor.exterieur_temperature') | int) <= 21 else
'F87E27' if (states('sensor.exterieur_temperature') | int) <= 27 else
'CF3927' if (states('sensor.exterieur_temperature') | int) <= 32 else
'A12527' }}"}
action: mqtt.publish
Thanks for your help.