CCOSTAN / Home-AssistantConfig

:house: Home Assistant configuration & Documentation for my Smart House. Write-ups, videos, part lists, and links throughout. Be sure to :star: it. Updated FREQUENTLY!
https://www.vCloudInfo.com
Other
4.72k stars 508 forks source link

logging rachio watering to MQTT sensor. #63

Closed CCOSTAN closed 7 years ago

CCOSTAN commented 7 years ago

Put it into a speech notification.

CCOSTAN commented 7 years ago

{{as_timestamp(states("sensor.date") ~ ' 00:00:00-05:00')|timestamp_custom('%A, %B %d', true)}}

Thanks @happyleavesaoc

CCOSTAN commented 7 years ago
- platform: template
  sensors:
   hot_water_off:
           friendly_name: 'Hot Water Off Timestamp'
           value_template: >-
                   {%- if states.binary_sensor.cv_hot_water_active.state == 'off' %}
                    {{ as_timestamp(states.binary_sensor.cv_hot_water_active.last_updated) }}
                    {%- else %}
                    {{ states('sensor.hot_water_off') }}
                    {%- endif %}
infernix commented 7 years ago

:+1:

Updated version:

- platform: template
  sensors:
   hot_water_on:
           friendly_name: 'Hot Water On Timestamp'
           value_template: >-
                   {%- if states.binary_sensor.cv_hot_water_active.state == 'on' %}
                    {{ as_timestamp(states.binary_sensor.cv_hot_water_active.last_changed) }}
                    {%- else %}
                    {{ states('sensor.hot_water_on') }}
                    {%- endif %}
- platform: template
  sensors:
   hot_water_off:
           friendly_name: 'Hot Water Off Timestamp'
           value_template: >-
                   {%- if states.binary_sensor.cv_hot_water_active.state == 'off' %}
                    {{ as_timestamp(states.binary_sensor.cv_hot_water_active.last_changed) }}
                    {%- else %}
                    {{ states('sensor.hot_water_off') }}
                    {%- endif %}

binary:

- platform: template
  sensors:
   hot_water_dehumidifier:
           friendly_name: 'Hot Water Dehumidifier'
           value_template: >-
                   {%- set duration = states.sensor.hot_water_off.state|int - states.sensor.hot_water_on.state|int -%}
                   {%- set seconds_since_on = as_timestamp(now())|int - states.sensor.hot_water_on.state|int -%}
                   {%- set seconds_since_off = as_timestamp(now())|int - states.sensor.hot_water_off.state|int -%}
                   {%- if states.binary_sensor.cv_hot_water_active.state == 'on'
                       and (seconds_since_on > 180 ) -%}
                   {{ True }}
                   {%- elif states.binary_sensor.cv_hot_water_active.state == 'off' 
                       and (seconds_since_off < ( duration * 2)) 
                       and (duration > 180) 
                       and states.sensor.hot_water_off.state != 'unknown' 
                       and states.sensor.hot_water_on.state != 'unknown' -%}
                   {{ True }}
                   {%- else -%}
                   {{ False }}
                   {%- endif %}
           entity_id:
                   - sensor.hot_water_on
                   - sensor.hot_water_off
                   - binary_sensor.cv_hot_water_active

Most notable change is to use last_changed not last_updated

CCOSTAN commented 7 years ago
{# Difference between dates in hours, roughly #}
      {% macro hour_diff(first, second) -%}
        {{((as_timestamp(first) - as_timestamp(second))/60.0/60.0)}}
      {%- endmacro %}