> {#- returns "true" if the name ends with 's' -#} {%- macro plural(name) -%} {{- "true" if name.endswith("s") else "false" -}} {%- endmacro -%} {#- Alerts low battery (below 50% at night), ONLY when the phone is not pluggedin -#} {%- macro low_battery_check() -%} {%- set level = 50 -%} {%- for item in states.device_tracker if 'life360_' in item.entity_id and state_attr(item.entity_id, "battery") |lower != "none" -%} {%- if item.attributes.battery|int < level -%} {%- if state_attr(item.entity_id, "battery_charging" ) != true %} {{- item.attributes.friendly_name | replace("life360", "") |title }}'s iPhone battery is at {{ item.attributes.battery }} percent. {%- endif %} {%- endif %} {%- endfor -%} {%- endmacro -%} {#- Provides Light Status -#} {%- macro light_status() -%} {%- set lights_switches = ["switch.basement_left", "switch.basement_right", "switch.frontyard_light", "switch.garage", "switch.srinika_bedroom", "switch.guest_room", "switch.hasika_bed_accent", "switch.hasika_bedroom", "switch.kitchen_switch", "switch.office_room", "switch.backyard_light"] %} {%- for item in lights_switches -%} {%- if states[item.split('.')[0]][item.split('.')[1]].state == "on" -%} {%- set friendly_name = states[item.split('.')[0]][item.split('.')[1]].attributes.friendly_name %} {%- if plural(friendly_name) == "true" %} {{- friendly_name }} are ON. {%- else -%} {{- friendly_name }} is ON. {%- endif -%} {%- endif -%} {%- endfor -%} {%- endmacro -%} {#- Provides Home Security System Status -#} {%- macro alarm_status() -%} {%- if states('alarm_control_panel.home') | lower == "disarmed" -%} Your home security system is switched OFF. You may want to turn it ON. {%- elif states('alarm_control_panel.home') | lower == "armed_away" -%} Your home security system is set to away mode. {%- elif states('alarm_control_panel.home') | lower == "armed_home" -%} Your home security system is ON, and your home is secured. {%- endif %} {%- endmacro -%} {#- Provides Trash and Recycle Reminder -#} {%- macro trash_recycle_status() -%} {%- set flag = false -%} {%- if states('sensor.trash_day') | lower == "yes" -%} Your trash will be picked up tomorrow. Did you leave the trash bin outside?. {%- set flag = true -%} {%- endif %} {%- if states('sensor.recycle_day') | lower == "yes" -%} {%- if flag -%} Also, your recycle stuff will be picked up tomorrow as well! Please leave both recycle bin and trash cans outside if you haven't!. {%- else -%} Your recycle stuff will be picked up tomorrow. Please leave the recycle bin outside if you haven't done so!. {%- endif -%} {%- endif %} {%- endmacro -%} {%- macro outside_weather() -%} {%- if states('sensor.dark_sky_minutely_summary') != "unknown" -%} Outside, it is going to be {{states('sensor.dark_sky_minutely_summary')}}. {%- endif -%} {%- if states('sensor.dark_sky_apparent_temperature') != "unknown" %} The temperature outside is around {{ states('sensor.dark_sky_apparent_temperature') | round(0)}} degrees. {%- endif -%} {%- endmacro -%} {%- macro pihole() -%} {%- if states('sensor.ads_blocked_today') |int > 100 -%} Our internet blocking system has blocked {{states('sensor.ads_blocked_today') }} ads today. {%- endif -%} {%- endmacro -%} {%- macro charging_status() -%} {%- for item in states if "life360_" in item.entity_id and item.attributes.battery_charging != True %} {%- if loop.first %}{% elif loop.last %} and {% else %}, {% endif -%}{{- item.name.split(' ')[1] |title -}} {%- endfor -%} {%- endmacro -%} {%- macro battery_status() -%} {% set value = charging_status() %} {% if ' and ' in value or ',' in value %} {{ value }}'s phones are not plugged in. {% elif value != '' %} {{ value }}'s phone is not plugged in. {% endif %} {%- endmacro -%} {#- Provides Garage Doors Status -#} {%- macro single_car_garage_door_status() -%} {% if states('binary_sensor.door_window_sensor_158d0004248d5b') |lower == "on" %} {{ states.binary_sensor.door_window_sensor_158d0004248d5b.attributes.friendly_name }} is OPEN {% endif %} {%- endmacro -%} {%- macro two_car_garage_door_status() -%} {% if states('binary_sensor.door_window_sensor_158d0004231f7b') |lower == "on" %} {{ states.binary_sensor.door_window_sensor_158d0004231f7b.attributes.friendly_name }} is OPEN {% endif %} {%- endmacro -%} {%- macro tesla_status() %} {%- if states("binary_sensor.tesla_model_3_charger_sensor") != "unknown" -%} Your Tesla Car is {{ 'not' if states('binary_sensor.tesla_model_3_charger_sensor') == "off" }} plugged in. {% endif %} {%- if states("sensor.tesla_model_3_battery_sensor") != "unknown" and states("sensor.tesla_model_3_range_sensor") != "unknown" and states('sensor.tesla_model_3_battery_sensor') | int > 0 -%} Tesla Car battery is at {{ states('sensor.tesla_model_3_battery_sensor') }}%, and you can drive about {{ (states.sensor.tesla_model_3_range_sensor.state | int) | round(0) }} miles. {% endif %} {%- endmacro %} {#- Check for low humidity levels in autumn, winter and high levels during rest of the year -#} {%- macro humidity_status() -%} {%- if states('sensor.season') | lower == "autumn" or states('sensor.season') | lower == "winter" %} {%- if states('sensor.dining_room_thermostat_humidity') | int < 30 -%} Home humidity is less than 30%. {%- endif -%} {% else %} {%- if states('sensor.dining_room_thermostat_humidity') | default(0) | int > 60 -%} Home humidity is more than 60%. {%- endif -%} {%- endif -%} {%- endmacro -%} {%- macro clean_up(data) -%} {%- for item in data.split("\n") if item | trim != "" -%} {{ item | trim }} {% endfor -%} {%- endmacro -%} {%- macro getGreeting() -%} {%- if greeting | default('yes', true ) == "yes" -%} {% if now().hour|int < 12 %} Have a great day! {% elif now().hour|int < 18 %} Enjoy your afternoon! {% elif now().hour|int < 20 %} Enjoy your evening! {% else %} Have a good night! {% endif %} {%- endif -%} {%- endmacro -%} {#- Main macro that runs all other macros and combines the information -#} {%- macro run_script() -%} It is {% if now().hour > 12 %}{{ now().hour | int - 12 }}: {{- now().minute }} PM{% else %}{{ now().hour }}: {{- now().minute }} PM{% endif %}. Here is the status of your home.{{- alarm_status() -}} {%- set battery_output = low_battery_check() -%} {%- if battery_output | trim != "" -%} {{- battery_output -}} Please make sure you put the phones to charge. {%- endif -%} {%- set light_output = light_status() -%} {%- if light_output | trim == "" -%} All the lights in the house are OFF. {%- else -%} {{- light_output -}} {%- endif -%} {%- set single_car_garage = single_car_garage_door_status() -%} {%- set two_car_garage = two_car_garage_door_status() -%} {%- if single_car_garage | trim == "" and two_car_garage | trim == "" -%} The garage doors are closed. {%- elif single_car_garage | trim != "" and two_car_garage | trim != "" -%} Warning! Both garage doors are OPEN. {% else %} Warning! {{ single_car_garage }} {{ two_car_garage }} {%- endif -%} {%- set trash_output = trash_recycle_status() -%}{{- trash_recycle_status() -}} {{- battery_status() -}} {{- tesla_status() -}} {{- humidity_status() -}} {{- outside_weather() }} Everything else looks good. {{ getGreeting() }} {%- endmacro -%} {{- clean_up(run_script()) -}}