2019-04-17 22:46:06 +00:00
>
{#- returns "true" if the name ends with 's' -#}
{%- macro plural(name) -%}
{{- "true" if name.endswith("s") else "false" -}}
{%- endmacro -%}
2020-02-09 23:33:06 +00:00
{#- Alerts low battery (below 50% at night), ONLY when the phone is not pluggedin -#}
2019-04-17 22:46:06 +00:00
{%- macro low_battery_check() -%}
2020-02-09 23:33:06 +00:00
{%- set level = 50 -%}
{%- for item in states.device_tracker if 'life360_' in item.entity_id and state_attr(item.entity_id, "battery") |lower != "none" -%}
2019-04-17 22:46:06 +00:00
{%- if item.attributes.battery|int < level -%}
2020-02-09 23:33:06 +00:00
{%- if state_attr(item.entity_id, "battery_charging" ) != true %}
2020-02-05 23:28:38 +00:00
{{- item.attributes.friendly_name | replace("life360", "") |title }}'s iPhone battery is at {{ item.attributes.battery }} percent.
2019-04-17 22:46:06 +00:00
{%- endif %}
{%- endif %}
{%- endfor -%}
{%- endmacro -%}
{#- Provides Light Status -#}
{%- macro light_status() -%}
{%- set lights_switches = ["light.family_room",
"light.master_bedroom" ,
"switch.basement_left" ,
"switch.basement_right" ,
"switch.frontyard_light" ,
"switch.garage" ,
"switch.guest_bedroom" ,
"switch.prayer_room" ,
"switch.kids_bed_accent" ,
"switch.kids_bedroom" ,
"switch.kitchen" ,
"switch.office_room" ,
"switch.wemobackyardlightswitch" ,
"switch.zwave_smart_switch_switch" ] %}
{%- 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() -%}
2020-02-05 23:28:38 +00:00
{%- if states('alarm_control_panel.home') | lower == "disarmed" -%}
2019-04-17 22:46:06 +00:00
Your home security system is switched OFF. You may want to turn it ON.
2020-02-05 23:28:38 +00:00
{%- elif states('alarm_control_panel.home') | lower == "armed_away" -%}
2019-04-17 22:46:06 +00:00
Your home security system is set to away mode.
2020-02-05 23:28:38 +00:00
{%- elif states('alarm_control_panel.home') | lower == "armed_home" -%}
2019-04-17 22:46:06 +00:00
Your home security system is ON, and your home is secured.
{%- endif %}
{%- endmacro -%}
2019-12-20 15:32:28 +00:00
2019-04-17 22:46:06 +00:00
{#- Provides Trash and Recycle Reminder -#}
{%- macro trash_recycle_status() -%}
{%- set flag = false -%}
2019-12-20 15:32:28 +00:00
{%- if states('sensor.trash_day') | lower == "yes" -%}
2019-04-17 22:46:06 +00:00
Your trash will be picked up tomorrow. Did you leave the trash bin outside?.
{%- set flag = true -%}
{%- endif %}
2019-12-20 15:32:28 +00:00
{%- if states('sensor.recycle_day') | lower == "yes" -%}
2019-04-17 22:46:06 +00:00
{%- 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 -%}
2019-12-20 15:32:28 +00:00
2019-04-17 22:46:06 +00:00
{%- 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" %}
2019-12-20 15:32:28 +00:00
The temperature outside is around {{ states('sensor.dark_sky_apparent_temperature') | round(0)}} degrees.
2019-04-17 22:46:06 +00:00
{%- endif -%}
{%- endmacro -%}
2019-12-20 15:32:28 +00:00
2019-04-17 22:46:06 +00:00
{%- macro pihole() -%}
2019-12-20 15:32:28 +00:00
{%- if states('sensor.ads_blocked_today') |int > 100 -%}
Our internet blocking system has blocked {{states('sensor.ads_blocked_today') }} ads today.
2019-04-17 22:46:06 +00:00
{%- endif -%}
{%- endmacro -%}
{%- macro charging_status() -%}
2020-02-09 23:33:06 +00:00
{%- 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 -}}
2019-04-17 22:46:06 +00:00
{%- 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() -%}
2019-12-20 15:32:28 +00:00
{% if states('binary_sensor.single_car_garage_door_tilt_sensor_sensor') |lower == "on" %}
2019-04-17 22:46:06 +00:00
{{ states.binary_sensor.single_car_garage_door_tilt_sensor_sensor.attributes.friendly_name }} is OPEN
{% endif %}
{%- endmacro -%}
2019-12-20 15:32:28 +00:00
2019-04-17 22:46:06 +00:00
{%- macro two_car_garage_door_status() -%}
2019-12-20 15:32:28 +00:00
{% if states('binary_sensor.two_car_garage_door_tilt_sensor_sensor') |lower == "on" %}
2019-04-17 22:46:06 +00:00
{{ states.binary_sensor.two_car_garage_door_tilt_sensor_sensor.attributes.friendly_name }} is OPEN
{% endif %}
{%- endmacro -%}
{%- macro tesla_status() %}
2020-02-05 23:28:38 +00:00
{%- 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.
2019-04-17 22:46:06 +00:00
{% endif %}
2020-02-05 23:28:38 +00:00
{%- 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.
2019-04-17 22:46:06 +00:00
{% endif %}
{%- endmacro %}
{#- Check for low humidity levels in autumn, winter and high levels during rest of the year -#}
{%- macro humidity_status() -%}
2019-12-20 15:32:28 +00:00
{%- if states('sensor.season') | lower == "autumn" or states('sensor.season') | lower == "winter" %}
{%- if states('sensor.dining_room_thermostat_humidity') | int < 30 -%}
2019-04-17 22:46:06 +00:00
Home humidity is less than 30%.
{%- endif -%}
{% else %}
2019-12-20 15:32:28 +00:00
{%- if states('sensor.dining_room_thermostat_humidity') | default(0) | int > 60 -%}
2019-04-17 22:46:06 +00:00
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 -%}
2019-12-20 15:32:28 +00:00
2019-04-17 22:46:06 +00:00
{{- clean_up(run_script()) -}}