Advertisement
sblantipodi

Untitled

Jan 18th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 4.20 KB | None | 0 0
  1. input_number:
  2.     alarm_1_hour:
  3.         name: Ore
  4.         icon: mdi:timer
  5.         initial: 8
  6.         min: 0
  7.         max: 23
  8.         step: 1
  9.     alarm_1_minutes:
  10.         name: Minuti
  11.         icon: mdi:timer
  12.         initial: 15
  13.         min: 0
  14.         max: 59
  15.         step: 1
  16.  
  17. input_boolean:
  18.     alarm_1_weekday:
  19.         name: Giorni lavorativi
  20.         initial: on
  21.         icon: mdi:calendar
  22.     alarm_1_weekend:
  23.         name: Weekends
  24.         initial: off
  25.         icon: mdi:calendar
  26.  
  27. sensor:
  28.     - platform: template
  29.       sensors:
  30.          alarm_1_time:
  31.               friendly_name: 'Sveglia'
  32.               value_template: >-
  33.                   {{ "%0.02d:%0.02d" | format(states("input_number.alarm_1_hour") | int, states("input_number.alarm_1_minutes") | int) }}
  34.          nextalarm:
  35.              friendly_name: Secondi fino al prossimo allarme
  36.              entity_id:
  37.              - input_number.alarm_1_hour
  38.               - input_number.alarm_1_minutes
  39.              value_template: >
  40.               {% set relative_time =  (states.input_number.alarm_1_hour.state|float|multiply(60) + states.input_number.alarm_1_minutes.state|float) - (now().hour|float|multiply(60) + now().minute) %}
  41.                {%- if relative_time < 0 -%}
  42.                         {{23*60+relative_time}}
  43.                {%- else -%}
  44.                         {{ relative_time-60}}
  45.                {%- endif %}
  46.          time_until_alarm:
  47.              friendly_name: Tempo fino alla prossima sveglia
  48.              entity_id:
  49.              - sensor.nextalarm
  50.              value_template: '{{  (states.sensor.nextalarm.state.split(" ")[0] | int *60 ) | timestamp_custom("%H:%M") }}'
  51.  
  52. group:
  53.     alarm_1:
  54.         name: Sveglia Smart
  55.         entities:
  56.            - sensor.alarm_1_time
  57.             - sensor.time_until_alarm
  58.             - input_number.alarm_1_hour
  59.             - input_number.alarm_1_minutes
  60.             - input_boolean.alarm_1_weekday
  61.             - input_boolean.alarm_1_weekend
  62.  
  63. automation:
  64.     - id: alarm_1_weekdays
  65.       hide_entity: true
  66.       alias: "Sveglia (giorni lavorativi)"
  67.       trigger:
  68.           - platform: time
  69.             minutes: '/1'
  70.             seconds: 0
  71.       condition:
  72.           - condition: state
  73.             entity_id: input_boolean.alarm_1_weekday
  74.             state: 'on'
  75.           - condition: time
  76.             weekday:
  77.                - mon
  78.                 - tue
  79.                 - wed
  80.                 - thu
  81.                 - fri
  82.           - condition: template
  83.             value_template: >-
  84.                 {{ now().strftime("%H:%M") == states.sensor.alarm_1_time.state }}
  85.       action:
  86.      # - service: media_player.play_media
  87.       #   entity_id: media_player.google_home_mini
  88.       #   data:
  89.       #     media_content_id: https://dpsoftware.duckdns.org/local/audio/ameno.mp3 #http://icecast.unitedradio.it/Virgin.mp3
  90.       #     media_content_type: audio/mp3 # audio/mp4
  91.       - data:
  92.           payload: '{"state": "ON", "brightness": 0, "color": {"r": 0, "g": 255, "b": 255},
  93.             "effect": "solid"}'
  94.           topic: lights/pcambiligh/set
  95.         service: mqtt.publish
  96.       - service: light.turn_on
  97.         data:
  98.           entity_id: light.pc_ambilight
  99.           brightness: 255
  100.           transition: 3000
  101.     - delay: 600 #600
  102.     - id: alarm_1_weekend
  103.       hide_entity: true
  104.       alias: "Sveglia (weekend)"
  105.       trigger:
  106.           - platform: time
  107.             minutes: '/1'
  108.             seconds: 0
  109.       condition:
  110.           - condition: state
  111.             entity_id: input_boolean.alarm_1_weekend
  112.             state: 'on'
  113.           - condition: time
  114.             weekday:
  115.                - sat
  116.                 - sun
  117.           - condition: template
  118.             value_template: >-
  119.                 {{ now().strftime("%H:%M") == states.sensor.alarm_1_time.state }}
  120.       action:
  121.       - data:
  122.           payload: '{"state": "ON", "brightness": 0, "color": {"r": 0, "g": 255, "b": 255},
  123.             "effect": "solid"}'
  124.           topic: lights/pcambiligh/set
  125.         service: mqtt.publish
  126.       - service: light.turn_on
  127.         data:
  128.           entity_id: light.pc_ambilight
  129.           brightness: 255
  130.           transition: 3000
  131.       - delay: 600 #600
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement