#########################################################################################################
# Wrote this code for @norien, where he wanted to set specific color to all the bulbs based on holiday
#########################################################################################################
# homeassistant:
#   customize:

#     script.set_random_color_2_all_bulbs:
#       hidden: false
#     script.light_set_color:
#       hidden: true

# input_label:
#   hue_color_lamp_1_random_color:
#     value: "no"
#   hue_color_lamp_2_random_color:
#     value: "no"
#   hue_color_lamp_3_random_color:
#     value: "no"

# group:
#   Family Room Hue Bulbs:
#     entities:
#       - light.hue_color_lamp_1
#       - light.hue_color_lamp_2
#       - light.hue_color_lamp_3
#   Input Labels:
#     entities:
#       - input_label.hue_color_lamp_1_random_color
#       - input_label.hue_color_lamp_2_random_color
#       - input_label.hue_color_lamp_3_random_color

# script:
#   set_random_color_2_all_bulbs:
#     sequence:
#       - condition: template
#         value_template: >
#             {%- macro get_next_entity_id() -%}
#               {%- for item in states.group.input_labels.attributes.entity_id if is_state(item, "no") -%}
#                 {{- "," if not loop.first-}}{{- item -}}{{-endif-}}
#               {%- endfor -%}
#             {%- endmacro -%}
#             {%- set entity_ids = get_next_entity_id() -%}
#             {% if entity_ids | trim != "" and entity_ids.split(',') | length | int == 0 %}
#               false
#             {% else %}
#               true
#             {% endif %}
#       - delay: '00:00:01'
#       - service: script.light_set_color
#         data_template:
#           entity_id: >-
#             {%- macro get_next_entity_id() -%}
#               {%- for item in states.group.input_labels.attributes.entity_id if is_state(item, "no") -%}
#                 {{- "," if not loop.first-}}{{- item -}}{{-endif-}}
#               {%- endfor -%}
#             {%- endmacro -%}
#             {%- set entity_ids = get_next_entity_id() -%}
#             {% if entity_ids | trim != "" %}
#               {%- if entity_ids.split(',') | length > 0 -%}
#                 {{- 'light.' ~ entity_ids.split(',')[0].split('.')[1].replace('_random_color', '') -}}
#               {%- endif -%}
#             {% endif %}
#           brightness: 254
#           r: '{{ "{0:d}".format(range(210, 238)|random) }}'
#           g: '{{ "{0:d}".format(range(100, 132)|random) }}'
#           b: '{{ "{0:d}".format(range(240, 254)|random) }}'

#   light_set_color:
#     sequence:
#       - condition: template
#         value_template: '{{ entity_id | trim != "" }}'
#       - condition: template
#         value_template: '{{ brightness | trim != "" }}'
#       - service: light.turn_on
#         data_template:
#           entity_id: '{{ entity_id }}'
#           brightness: '{{ brightness }}'
#           rgb_color: ['{{"{0:d}".format(range(210, 238)|random)|int}}', '{{"{0:d}".format(range(210, 238)|random)|int}}', '{{"{0:d}".format(range(210, 238)|random)|int}}']
#       - service: input_label.set_value
#         data_template:
#           entity_id: "input_label.{{- entity_id.split('.')[1] -}}_random_color"
#           value: 'yes'
#       - delay: '00:00:01'
#       - service: script.set_random_color_2_all_bulbs

#########################################################################################################
# Wrote this for @chags, to show how to raise and handle custom events with dynamic data using templates
#########################################################################################################
# automation:
#   - alias: Fire Event
#     trigger:
#       platform: state
#       entity_id: switch.kitchen
#     action:
#       event: my_test_event
#       event_data:
#         foo: "bar"

#   - alias: Capture Event
#     trigger:
#       platform: event
#       event_type: my_test_event
#     action:
#       - service: script.notify_me
#         data_template:
#           message: "Test Event Captured with data foo: {{ trigger.event.data.foo }}"

#########################################################################################################
# Wrote this code for @roystervi, where it turns on a group of media players/speakers based on where
# the motion is detected, and when there is no motion, it turns off the speakers
#########################################################################################################

# automation:
#   - alias: Speakers On During Presence
#     trigger:
#       - platform: state
#         entity_id:
#           - binary_sensor.masterbed_motion
#           - binary_sensor.masterbath_motion
#           - binary_sensor.bathm_motion
#           - binary_sensor.kitchen_motion
#           - binary_sensor.den_motion
#     action:
#       - service_template: 'switch.turn_{{ trigger.to_state.state }}'
#         data_template:
#             entity_id: '{{ trigger.entity_id.replace("binary_sensor", "group") }}'

#########################################################################################################
# Wrote this code for someone, to help set scenes based on sun elevation and time combination
#########################################################################################################

#- id: Sunset_if_home
# automation:
#   - alias: 'Hemkomst'
#     trigger:
#       platform: state
#       entity_id: 'group.telefoner'
#       state: 'home'
#     condition:
#       - condition: time
#         after: '12:00:00'
#         before: '02:00:00'
#     action:
#       - service_template: scene.turn_on
#         data_template:
#           entity_id: >-
#             {%set elevation = states.sun.sun.attributes.elevation | int %}
#             {% if elevation > -10 and elevation | int < 5 %}
#               scene.normalvit
#             {% elif elevation | int > 5 %}
#               scene.dimmad_vit
#             {% endif %}

#########################################################################################################
# Wrote this code for someone, to show servcie_template example
#########################################################################################################

# automation:
#   - alias: Run every 15 seconds
#     initial_state: true
#     trigger:
#       - platform: time_pattern
#         seconds: '/15'
#     action:
#       - service_template: >-
#           {% if states.switch.kitchen.state == 'on' %}
#           switch.turn_off
#           {% else %}
#           switch.turn_on
#           {% endif %}
#         entity_id: switch.kitchen

#########################################################################################################
# Wrote this code for someone, where they wanted to drop a message to MQTT with topic name based on sensor
#########################################################################################################

# automation:
#   - alias: ResetMotionSensors
#     trigger:
#       - platform: state
#         entity_id: binary_sensor.hallway_motion
#         to: 'on'
#         for:
#           seconds: 30
#       - platform: state
#         entity_id: binary_sensor.livingroom_motion
#         to: 'on'
#         for:
#           seconds: 30
#       - platform: state
#         entity_id: binary_sensor.kitchen_motion
#         to: 'on'
#         for:
#           seconds: 30
#     action:
#       - service: mqtt.publish
#         data_template:
#           payload: '{"state": "open"}'
#           topic: >-
#             {% set mapping = '{ "hallway": "985335", "livingroom": "854267", "kitchen": "699555" }' %}
#             {{ 'Hassio/433/Honeywell/Honeywell_Door/Window_Sensor/' ~ mapping[trigger.entity_id.split('.')[1].split('_')[0] ~ ''] }}

#########################################################################################################
# Wrote code for @chags - to pass a list of variables from an automation to a script
#########################################################################################################

# automation:
#   - alias: 'Pass list to script'
#     trigger:
#       - platform: state
#         entity_id: switch.kitchen
#     action:
#       - service: script.test_script
#         data:
#           entities_list:
#             - light.hue_color_lamp_1
#             - light.hue_color_lamp_2
#             - light.hue_color_lamp_3
# script:
#   test_script:
#     sequence:
#       - service_template: light.turn_on
#         data_template:
#           entity_id: >
#             {% for e in entities_list %}
#             {%- if loop.first %}{% elif loop.last %}, {% else %}, {% endif -%}
#             {{ e }}
#             {%- endfor %}

#########################################################################################################
# Wrote code for @IxsharpxI#4883 - he wanted to call REST api and extract various values for APCUPS!
#########################################################################################################

# https://raw.githubusercontent.com/awesome-automations/home/master/apcups.html

# sensor:
#   - platform: rest
#     resource: https://raw.githubusercontent.com/awesome-automations/home/master/apcups.html
#     name: BATTERY_MODEL
#     scan_interval: 60
#     value_template: >
#       {%- macro GetValue(str) -%}
#       {%- if str in value -%}
#         {%- set index = value.split(str)[0]|length -%}
#         {{ value[index+str|length:value|length].split('\n')[0] }}
#       {%- endif -%}
#       {%- endmacro %}
#       {{ GetValue('MODEL    : ') }}

#########################################################################################################
# Wrote this code for someone, where they wanted to have an input_boolean that controls effects
#########################################################################################################

# input_boolean:
#   color_loop:
#     initial: off

# automation:
#   - alias: Colorloop Automation
#     trigger:
#       - platform: state
#         entity_id: input_boolean.color_loop
#     action:
#       - service_template: script.color_loop_ "{{- trigger.to_state.state -}}"

# script:
#   color_loop_on:
#     sequence:
#       - service: light.turn_on
#         data:
#           entity_id: light.xxx
#           effect: colorloop

#   color_loop_off:
#     sequence:
#       - service: light.turn_off
#         entity_id: light.xxx

#########################################################################################################
# @xxKira wanted to call a service in a loop by passing an alphabet each time from a string,
# so that the service inserts that alphabet using remote on TV
#########################################################################################################

# homeassistant:

# input_number:
#   text_index:
#     name: "Text Index"
#     initial: 0
#     min: 0
#     max: 255

# script:
#   input_text:
#     alias: Text to Enter on Remote
#     sequence:
#       - service_template: script.text_loop
#         data_template:
#           text: "Netflix"

#   text_loop:
#     alias: Loops Text
#     sequence:
#       - condition: template
#         value_template: "{{ 'true' if (states.input_number.text_index.state |int < text|length | int) else 'false' }}"
#       - service_template: script.key_input
#         data_template:
#           command: >-
#             {%- set index = states.input_number.text_index.state | int -%}
#             {{ text[index:index+1] }}
#           text: "{{ text }}"

#   key_input:
#     alias: Send Key Input
#     sequence:
#       - service: media_player.firetv_adb_shell
#         data_template:
#           entity_id: media_player.televisione_camera
#           cmd: "input keyevent {{ command | upper }}"
#       - delay: '00:00:01'
#       - service: input_number.set_value
#         data_template:
#           entity_id: input_number.text_index
#           value: "{{ (states.input_number.text_index.state | int + 1) }}"
#       - service: script.text_loop
#         data_template:
#           text: "{{ text }}"

#########################################################################################################
# Wrote this for @quadflight - automation alerts when any of the sensor's battery is less than 25
# it announces in the house!
#########################################################################################################
# automation:
#   - alias: Alert Low Battery
#     trigger:
#       - platform: template
#         value_template: >
#           {% set ns = namespace(lowBattery=false) %}
#           {%- for x in states if x.attributes and x.attributes.battery_level and x.attributes.battery_level |int <= 24 %}
#           {% set ns.lowBattery = true %}{% endfor %}
#           {{ ns.lowBattery }}
#     action:
#       - service: script.voice_notify
#         data_template:
#           message: >
#             {% set ns = namespace(lowBattery) %}
#             {%- for x in states if x.attributes and x.attributes.battery_level and x.attributes.battery_level |int <= 24 %}
#               {% set ns.lowBattery = ns.lowBattery ~ ',' ~ x.name %}
#             {%- endfor %}
#             {{ ns.lowBattery -}}
#             {{- ' battery is ' if ns.lowBattery.split(',')|count == 1 else ' batteries are ' -}} less than 25 percent.

##############################################################################################################################
# Wrote this for @marmar63#0271 - he wanted to run a script `x` number of times
# - reduce volume, restore volume level...etc
#
##############################################################################################################################
# input_number:
#   loop_index:
#     initial: 0
#     min: 0
#     step: 1
#     max: 9999

# script:
#   run_x_times:
#     alias: Run X Times
#     sequence:
#       - service: input_number.set_value
#         data_template:
#           entity_id: input_number.loop_index
#           value: 0
#       - service_template: script.loop_one
#         data_template:
#           count: "{{ count }}"

#   loop_one:
#     alias: Loops X times
#     sequence:
#       - condition: template
#         value_template: "{{ 'true' if (states.input_number.loop_index.state |int < count | int) else 'false' }}"
#       - service: mqtt.publish
#         data_template:
#           topic: "/loop/test"
#           payload: "{{ states.input_number.loop_index.state | int }}"
#           retain: false
#       - delay: '00:00:00'
#       - service: script.loop_two
#         data_template:
#           count: "{{ count |int}}"

#   loop_two:
#     alias: A loop that calls first loop
#     sequence:
#       - delay: '00:00:00'
#       - service: input_number.set_value
#         data_template:
#           entity_id: input_number.loop_index
#           value: "{{ (states.input_number.loop_index.state | int + 1) |int }}"
#       - service: script.loop_one
#         data_template:
#           count: "{{ count|int }}"

#######################################################################
# Package for Robotic mower named Bob
# https://www.robonect-shop.de/
#######################################################################

# homeassistant:
# #
#   customize:

#     group.robotic_mower:
#       icon: mdi:signal-variant
#       friendly_name: Robotgräsklippare
#       assumed_state: false
# #
#     group.robotic_mower_scheduling:
#       icon: mdi-calendar-clock
#       friendly_name: Robotgräsklippare Schemaläggning
#       assumed_state: false
# #
#     group.robotic_mower_automations:
#       icon: mdi:signal-variant
#       friendly_name: Robotgräsklippare automation
#       assumed_state: false
# #
#     input_datetime.bob_start_time_7:
#       friendly_name: Starttid Söndag
#       assumed_state: false
# #
#     input_datetime.bob_stop_time_7:
#       friendly_name: Stopptid Söndag
#       assumed_state: false
# #
#   customize_domain:
#     input_datetime:
#       icon: mdi:calendar-clock
# #
#   customize_glob:
#     "automation.bob_run_start*":
#       icon: mdi:calendar-check

#     "automation.bob_run_stop*":
#       icon: mdi:calendar-remove

# ######################################################################
# ## Group
# ######################################################################
# group:

#   robotic_mower:
#     view: no
#     name: Robotic Mower
#     control: hidden
#     entities:
#       - input_select.bob_command
#       - binary_sensor.bob
#       - sensor.bob_battery
#       - sensor.bob_battery_voltage
#       - sensor.bob_mode_raw
#       - sensor.bob_operating_voltage_mower
#       - sensor.bob_operating_voltage_robonect
#       - sensor.bob_operation_hours
#       - sensor.bob_status_friendly
#       - sensor.bob_status_raw
#       - sensor.bob_stopped
#       - sensor.bob_time_in_current_status
#       - sensor.bob_wifi_signal
#       - sensor.bob_humidity
#       - sensor.bob_temperature
#       - sensor.robotic_mower_name
#       - sensor.robotic_mower_serial

#   robotic_mower_scheduling:
#     view: no
#     name: 'Robotic mower scheduling'
#     control: hidden
#     entities:
#       - input_datetime.bob_start_time
#       - input_datetime.bob_stop_time
#       - input_datetime.bob_start_time_2
#       - input_datetime.bob_stop_time_2
#       - input_datetime.bob_start_time_3
#       - input_datetime.bob_stop_time_3
#       - input_datetime.bob_start_time_4
#       - input_datetime.bob_stop_time_4
#       - input_datetime.bob_start_time_5
#       - input_datetime.bob_stop_time_5
#       - input_datetime.bob_start_time_6
#       - input_datetime.bob_stop_time_6
#       - input_datetime.bob_start_time_7
#       - input_datetime.bob_stop_time_7

#   robotic_mower_automations:
#     view: no
#     name: 'Robotic mower Automations'
#     control: hidden
#     entities:
#       - automation.bob_nofity_front_collision
#       - automation.bob_command_control
#       - automation.bob_command_control_mode
#       - automation.bob_run_start
#       - automation.bob_run_stop
#       - automation.bob_run_start
#       - automation.bob_run_start_2
#       - automation.bob_run_start_2
#       - automation.bob_run_start_3
#       - automation.bob_run_start_4
#       - automation.bob_run_start_5
#       - automation.bob_run_start_6
#       - automation.bob_run_start_7
#       - automation.bob_run_stop
#       - automation.bob_run_stop_2
#       - automation.bob_run_stop_3
#       - automation.bob_run_stop_4
#       - automation.bob_run_stop_5
#       - automation.bob_run_stop_6
#       - automation.bob_run_stop_7
#       # - automation.set_bob_mode_selector
# ######################################################################
# # Sensor
# ######################################################################
# sensor:

#   - platform: mqtt
#     state_topic: "robotic_mower/mower/battery/charge"
#     name: "Bob Battery"
#     #unit_of_measurement: '%'
#     device_class: battery

#   - platform: mqtt
#     state_topic: "robotic_mower/mower/stopped"
#     name: "Bob Stopped"

#   - platform: mqtt
#     state_topic: "robotic_mower/wlan/rssi"
#     name: "Bob wifi signal"
#     #unit_of_measurement: 'dBm'
#     icon: mdi:signal-variant

#   - platform: mqtt
#     state_topic: "robotic_mower/mower/status"
#     name: "Bob status raw"

#   - platform: template
#     sensors:
#       bob_status_friendly:
#         friendly_name: "Bob Status"
#         value_template: >
#           {% if is_state("sensor.bob_status_raw", "1") -%}
#             Parked
#           {% elif is_state("sensor.bob_status_raw", "2") -%}
#             Mowing
#           {% elif is_state("sensor.bob_status_raw", "4") -%}
#             Charging
#           {% elif is_state("sensor.bob_status_raw", "5") -%}
#             Searching
#           {% elif is_state("sensor.bob_status_raw", "17") -%}
#             Sleeping
#           {% elif is_state("sensor.bob_status_raw", "3") -%}
#             Heading Home
#           {% elif is_state("sensor.bob_status_raw", "7") -%}
#             Front Collision
#           {% else -%}
#             Figure out what state {{ states("sensor.bob_status_raw") }} means
#           {%- endif %}

#   - platform: mqtt
#     state_topic: "robotic_mower/mower/status/duration"
#     name: "Bob time in current status"
#     #unit_of_measurement: 'minutes'

#   - platform: mqtt
#     state_topic: "robotic_mower/mower/mode"
#     name: "Bob mode raw"

#   - platform: mqtt
#     state_topic: "robotic_mower/mower/statistic/hours"
#     name: "Bob Operation Hours"
#     #unit_of_measurement: 'hours'
#     icon: mdi:timer-sand

#   - platform: mqtt
#     state_topic: 'robotic_mower/health/voltage/int33'
#     name: "Bob Operating Voltage Robonect"
#     #unit_of_measurement: '%'

#   - platform: mqtt
#     state_topic: 'robotic_mower/health/voltage/ext33'
#     name: "Bob Operating Voltage Mower"
#     #unit of measurement: '%'

#   - platform: mqtt
#     state_topic: 'robotic_mower/health/voltage/batt'
#     name: "Bob Battery Voltage"
#     #unit_of_measurement: '%'

#   - platform: mqtt
#     state_topic: "robotic_mower/health/climate/temperature"
#     name: "Bob temperature"
#     #unit_of_measurement: '°C'
#     device_class: temperature

#   - platform: mqtt
#     state_topic: "robotic_mower/health/climate/humidity"
#     name: "Bob humidity"
#     #unit_of_measurement: '%'
#     device_class: humidity

#   - platform: mqtt
#     state_topic: "robotic_mower/device/name"
#     name: "Robotic mower name"

#   - platform: mqtt
#     state_topic: "robotic_mower/device/serial"
#     name: "Robotic mower Serial"

# ###########################################################
# ## binary_sensor
# ###########################################################
# binary_sensor:

#   - platform: mqtt
#     name: "Bob"
#     state_topic: "robotic_mower/mqtt"
#     payload_on: "online"
#     payload_off: "offline"
#     device_class: "connectivity"
#  ###########################################################
#  ## input select
#  ###########################################################
# input_select:
#   bob_command:
#     name: Bob Set State
#     options:
#      - status_quo
#      - start
#      - stop
#      - auto
#      - home
#      - man
#      - eod
#     initial: status_quo
#     icon: mdi:robot

# ################################################################
# # Input datetime
# ################################################################
# input_datetime:
#   bob_start_time:
#     name: Bob Start Time
#     has_date: false
#     has_time: true

#   bob_stop_time:
#     name: Bob Stop Time
#     has_date: false
#     has_time: true

#   bob_start_time_2:
#     name: Bob Start Time 2
#     has_date: false
#     has_time: true

#   bob_stop_time_2:
#     name: Bob Stop Time 2
#     has_date: false
#     has_time: true

#   bob_start_time_3:
#     name: Bob Start Time 3
#     has_date: false
#     has_time: true

#   bob_stop_time_3:
#     name: Bob Stop Time 3
#     has_date: false
#     has_time: true

#   bob_start_time_4:
#     name: Bob Start Time 4
#     has_date: false
#     has_time: true

#   bob_stop_time_4:
#     name: Bob Stop Time 4
#     has_date: false
#     has_time: true

#   bob_start_time_5:
#     name: Bob Start Time 5
#     has_date: false
#     has_time: true

#   bob_stop_time_5:
#     name: Bob Stop Time 5
#     has_date: false
#     has_time: true

#   bob_start_time_6:
#     name: Bob Start Time 6
#     has_date: false
#     has_time: true

#   bob_stop_time_6:
#     name: Bob Stop Time 6
#     has_date: false
#     has_time: true

#   bob_start_time_7:
#     name: Bob Start Time 7
#     has_date: false
#     has_time: true

#   bob_stop_time_7:
#     name: Bob Stop Time 7
#     has_date: false
#     has_time: true

# ################################################################
# # Automation
# ################################################################
# automation:

#   - alias: Bob Command Control
#     initial_state: 'on'
#     trigger:
#       - platform: state
#         entity_id: input_select.bob_command
#         from: status_quo
#         to: start
#       - platform: state
#         entity_id: input_select.bob_command
#         from: status_quo
#         to: stop
#     action:
#       - service: mqtt.publish
#         data:
#           payload_template: '{{ states(''input_select.bob_command'') }}'
#           topic: robotic_mower/control
#       - service: input_select.select_option
#         data:
#           entity_id: input_select.bob_command
#           option: status_quo
# #
#   - alias: Bob Command Control Mode
#     initial_state: 'on'
#     trigger:
#       - platform: state
#         entity_id: input_select.bob_command
#         from: status_quo
#         to: auto
#       - platform: state
#         entity_id: input_select.bob_command
#         from: status_quo
#         to: home
#       - platform: state
#         entity_id: input_select.bob_command
#         from: status_quo
#         to: man
#       - platform: state
#         entity_id: input_select.bob_command
#         from: status_quo
#         to: eod
#     action:
#       - service: mqtt.publish
#         data:
#           payload_template: '{{ states(''input_select.bob_command'') }}'
#           topic: robotic_mower/control/mode
#       - service: input_select.select_option
#         data:
#           entity_id: input_select.bob_command
#           option: status_quo

# # #automation.set_bob_mode_selector
#   # - alias: Set Bob Mode Selector
#     # initial_state: 'on'
#     # trigger:
#       # - platform: mqtt
#         # topic: "robotic_mower/control/mode"
#     # action:
#       # - service: input_select.select_option
#         # data_template:
#           # entity_id: input_select.bob_command
#           # option: "{{ trigger.payload }}"

# #automation.bob_nofity_front_collision
#   - alias: 'Bob nofity Front Collision'
#     initial_state: 'on'
#     trigger:
#       - platform: state
#         entity_id: sensor.bob_status_friendly
#         to: 'Front Collision'
#     action:
#       - service: notify.leandro
#         data_template:
#          message: "Robotgräsklippare har kolliderat"
#          data:
#           priority: '1'
#           sound: updown
#       - service: media_player.volume_set
#         entity_id:
#           - media_player.living_room
#           - media_player.kitchen
#           - media_player.upstairs
#         data:
#           volume_level: '0.7'
#       - service: notify.alexa_media
#         data_template:
#           data:
#             type: announce
#             method: speak
#           target:
#           - media_player.living_room
#           - media_player.kitchen
#           - media_player.upstairs
#           message: >
#             Warning {{ trigger.to_state.attributes.name}} is now {{  trigger.to_state.attributes.state  }}
# #

# ################################################################################
# ## automation scheduling
# ################################################################################
# #Bob Run Start
# ################################################################################
# #Bob Run 1
#   - alias: Bob Run Start
#     initial_state: 'off'
#     trigger:
#     - platform: template
#       value_template: "{{ states('sensor.time') == (states.input_datetime.bob_start_time.attributes.timestamp | int | timestamp_custom('%H:%M', False)) }}"
#     action:
#       - service: mqtt.publish
#         data:
#           payload: 'start'
#           topic: 'robotic_mower/control'

#   - alias: Bob Run Stop
#     initial_state: 'off'
#     trigger:
#     - platform: template
#       value_template: "{{ states('sensor.time') == (states.input_datetime.bob_stop_time.attributes.timestamp | int | timestamp_custom('%H:%M', False)) }}"
#     action:
#       - service: mqtt.publish
#         data:
#           payload: 'stop'
#           topic: 'robotic_mower/control'
# #Bob Run 2
#   - alias: Bob Run Start 2
#     initial_state: 'off'
#     trigger:
#     - platform: template
#       value_template: "{{ states('sensor.time') == (states.input_datetime.bob_start_time_2.attributes.timestamp | int | timestamp_custom('%H:%M', False)) }}"
#     action:
#       - service: mqtt.publish
#         data:
#           payload: 'start'
#           topic: 'robotic_mower/control'

#   - alias: Bob Run Stop 2
#     initial_state: 'off'
#     trigger:
#     - platform: template
#       value_template: "{{ states('sensor.time') == (states.input_datetime.bob_stop_time_2.attributes.timestamp | int | timestamp_custom('%H:%M', False)) }}"
#     action:
#       - service: mqtt.publish
#         data:
#           payload: 'stop'
#           topic: 'robotic_mower/control'
# #Bob Run 3
#   - alias: Bob Run Start 3
#     initial_state: 'off'
#     trigger:
#     - platform: template
#       value_template: "{{ states('sensor.time') == (states.input_datetime.bob_start_time_3.attributes.timestamp | int | timestamp_custom('%H:%M', False)) }}"
#     action:
#       - service: mqtt.publish
#         data:
#           payload: 'start'
#           topic: 'robotic_mower/control'

#   - alias: Bob Run Stop 3
#     initial_state: 'off'
#     trigger:
#     - platform: template
#       value_template: "{{ states('sensor.time') == (states.input_datetime.bob_stop_time_3.attributes.timestamp | int | timestamp_custom('%H:%M', False)) }}"
#     action:
#       - service: mqtt.publish
#         data:
#           payload: 'stop'
#           topic: 'robotic_mower/control'
# #Bob Run 4
#   - alias: Bob Run Start 4
#     initial_state: 'off'
#     trigger:
#     - platform: template
#       value_template: "{{ states('sensor.time') == (states.input_datetime.bob_start_time_4.attributes.timestamp | int | timestamp_custom('%H:%M', False)) }}"
#     action:
#       - service: mqtt.publish
#         data:
#           payload: 'start'
#           topic: 'robotic_mower/control'

#   - alias: Bob Run Stop 4
#     initial_state: 'off'
#     trigger:
#     - platform: template
#       value_template: "{{ states('sensor.time') == (states.input_datetime.bob_stop_time_4.attributes.timestamp | int | timestamp_custom('%H:%M', False)) }}"
#     action:
#       - service: mqtt.publish
#         data:
#           payload: 'stop'
#           topic: 'robotic_mower/control'
# #Bob Run 5
#   - alias: Bob Run Start 5
#     initial_state: 'off'
#     trigger:
#     - platform: template
#       value_template: "{{ states('sensor.time') == (states.input_datetime.bob_start_time_5.attributes.timestamp | int | timestamp_custom('%H:%M', False)) }}"
#     action:
#       - service: mqtt.publish
#         data:
#           payload: 'start'
#           topic: 'robotic_mower/control'

#   - alias: Bob Run Stop 5
#     initial_state: 'off'
#     trigger:
#     - platform: template
#       value_template: "{{ states('sensor.time') == (states.input_datetime.bob_stop_time_5.attributes.timestamp | int | timestamp_custom('%H:%M', False)) }}"
#     action:
#       - service: mqtt.publish
#         data:
#           payload: 'stop'
#           topic: 'robotic_mower/control'
# #Bob Run 6
#   - alias: Bob Run Start 6
#     initial_state: 'off'
#     trigger:
#     - platform: template
#       value_template: "{{ states('sensor.time') == (states.input_datetime.bob_start_time_6.attributes.timestamp | int | timestamp_custom('%H:%M', False)) }}"
#     action:
#       - service: mqtt.publish
#         data:
#           payload: 'start'
#           topic: 'robotic_mower/control'

#   - alias: Bob Run Stop 6
#     initial_state: 'off'
#     trigger:
#     - platform: template
#       value_template: "{{ states('sensor.time') == (states.input_datetime.bob_stop_time_6.attributes.timestamp | int | timestamp_custom('%H:%M', False)) }}"
#     action:
#       - service: mqtt.publish
#         data:
#           payload: 'stop'
#           topic: 'robotic_mower/control'
# #Bob Run 7
#   - alias: Bob Run Start 7
#     initial_state: 'off'
#     trigger:
#     - platform: template
#       value_template: "{{ states('sensor.time') == (states.input_datetime.bob_start_time_7.attributes.timestamp | int | timestamp_custom('%H:%M', False)) }}"
#     condition:
#       - condition: time
#         weekday:
#           - sun
#     action:
#       - service: mqtt.publish
#         data:
#           payload: 'start'
#           topic: 'robotic_mower/control'

#   - alias: Bob Run Stop 7
#     initial_state: 'off'
#     trigger:
#     - platform: template
#       value_template: "{{ states('sensor.time') == (states.input_datetime.bob_stop_time_7.attributes.timestamp | int | timestamp_custom('%H:%M', False)) }}"
#     condition:
#       - condition: time
#         weekday:
#           - sun
#     action:
#       - service: mqtt.publish
#         data:
#           payload: 'stop'
#           topic: 'robotic_mower/control'

# sensor:
#   - platform: rest
#     resource: https://pollenkontroll.no/api/pollen-count?country=no&location=126
#     name: Pollen
#     value_template: >-
#       {% for city in value_json.cities if city.id == '126' %}
#       {{ city.id }}
#       {% endfor %}

# homeassistant:

# script:
#   sync_ecobee_temp:
#     alias: Push Ecobee target temp to the other thermostats
#     sequence:
#       - service: climate.set_temperature
#         data_template:
#           entity_id: climate.cooler_fan
#           temperature: "{{ states.climate.main_floor.temperature |float }}"

# automation:
#   - id: sensor
#     alias: sensor
#     trigger:
#       - platform: state
#         entity_id: binary_sensor.door
#         from: "off"
#         to: "on"
#         for: "00:00:10"
#     action:
#       - service_template: "homeassistant.turn_{{- 'off' if trigger.to_state.state == 'on' else 'on' }}"
#         entity_id: switch.luce_corridoio

# homeassistant:
# group:
#   kitchen:
#     name: Kitchen
#     entities:
#       - light.family_room
#       - light.gateway_light_34ce008ad65d
#       - light.hue_color_lamp_1
#       - light.hue_color_lamp_2
#       - light.hue_color_lamp_3
#       - light.master_bedroom
#       - light.master_bedroom_1
#       - light.master_bedroom_2

# - alias: "doods fremme video"
#   trigger:
#     platform: state
#     entity_id: image_processing.doods_fremme
#   #  condition:
#   #    condition: template
#   #    value_template: "{{ 'person' in state_attr('image_processing.doods_fremme', 'summary') }}"
#   action:
#     - service: input_boolean.toggle
#       entity_id: input_boolean.dummy
#     - service: camera.record
#       data_template:
#         entity_id: camera.fremme
#         filename: "/tmp/{{- trigger.entity_id.split('.')[1].split('_')[1] -}}_{{- states.input_boolean.dummy_fremme.last_updated.strftime('%Y%m%d-%H%M%S') -}}.mp4"
#         duration: 20
#         lookback: 10
#     - delay: "00:00:20"
#     - service: notify.eirikz_telegram
#       data_template:
#         title: "Doods"
#         message: "fremme"
#         data:
#           video:
#             file: "/tmp/{{- trigger.entity_id.split('.')[1].split('_')[1] -}}_{{- states.input_boolean.dummy_fremme.last_updated.strftime('%Y%m%d-%H%M%S') -}}.mp4"

# homeassistant:

# input_boolean:
#   dummy_fremme:
#     name: "Dummy Fremme Input Boolean!"
#     icon: mdi:sticker-emoji
#     initial: on

# input_label:
#   file_1:
#   file_2:

# automation:
#   - alias: "my test"
#     initial_state: "on"
#     trigger:
#       platform: state
#       entity_id: switch.kitchen
#     action:
#       - service: input_boolean.toggle
#         entity_id: input_boolean.dummy
#       - service: input_label.set_value
#         data_template:
#           entity_id: "input_label.file_1"
#           value: "/tmp/{{- trigger.entity_id.split('.')[1] -}}_{{- states.input_boolean.dummy.last_updated.strftime('%Y%m%d-%H%M%S') -}}.mp4"
#       - delay: "00:00:05"
#       - service: input_label.set_value
#         data_template:
#           entity_id: "input_label.file_2"
#           value: "/tmp/{{- trigger.entity_id.split('.')[1] -}}_{{- states.input_boolean.dummy.last_updated.strftime('%Y%m%d-%H%M%S') -}}.mp4"


# {% for x in states if 'sensor.illumination_' in x.entity_id %}
# {{ x.name}} - {{ x.attributes.battery_level }}
# {%- endfor %}

# {% for x in states if 'sensor.battery_' in x.entity_id %}
# {{ x.name}} - {{ x.state }}
# {%- endfor %}