No real coding; all native HA stuff. For example, here’s how I keep track of how long the air conditioner has been on for:
- The Honeywell thermostat platform is defined in configuration.yaml:
climate:
- platform: honeywell
username: [email protected]
password: Password
scan_interval: 180
This platform does C2C with the Honeywell server to get the names and attributes of my thermostats. These become climate entities in HA. Of course any integration which results in a climate entity would work. My 1st floor thermostat’s name in HA becomes:
climate.1st_floor
- I use a template platform (again in configuration.yaml) to create a sensor called 1st_floor_action, which gets the attribute hvac_action from the first floor thermostat:
sensor:
- platform: template
sensors:
1st_floor_action:
friendly_name: "1st Floor Action"
value_template: "{{ state_attr('climate.1st_floor', 'hvac_action') }}"
Later in the same section (sensors:) I define two history_stats entities:
- platform: history_stats
name: AC on today
entity_id: sensor.1st_floor_action
state: 'cooling'
type: time
start: '{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}'
end: '{{ now() }}'
- platform: history_stats
name: AC on yesterday
entity_id: sensor.1st_floor_action
state: 'cooling'
type: time
end: '{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}'
duration:
hours: 24
The first one totals how long the hvac_action was cooling, from midnight until now.
The second one totals up all of yesterday’s cooling.
You can display these numerically or as a chart in Lovelace.
- I added a notify: section in configuration.yaml defining a file platform with a file name of ac_summary.txt:
notify:
- platform: file
name: ac_summary
filename: ac_summary.txt
timestamp: False
- I set up an automation to run early in the morning and write the value to this text file.
The autmation looks more complicated than it is. I’ve set multiple triggers so if HA is off line at 1:04 AM when I want it to run, it’ll try again a couple more times. Then I have a condition which verifies that the last_triggered date isn’t today, so it’ll only run once.
The important part is the action: section, where the date and ac_on_yesterday value are written to the file using notify.ac_summary.
- id: id_ac_summary
alias: ac Summary
trigger:
- at: 01:04:00
platform: time
- at: 02:04:00
platform: time
- at: '14:04:00'
platform: time
condition:
- condition: template
value_template: '{{ now().strftime(''%x'') != as_timestamp(states.automation.ac_summary.attributes.last_triggered)
| timestamp_custom(''%D'') }}'
action:
- data_template:
message: '{{ now().strftime(''%x'') }},{{ states.sensor.ac_on_yesterday.state
}}'
service: notify.ac_summary
The resulting text file looks something like this:
Home Assistant notifications (Log started: 2020-06-06T05:04:00.043849+00:00)
--------------------------------------------------------------------------------
07/09/20,2.72
07/10/20,2.76
07/11/20,0.96
This format is pretty easy to import into or link from any spreadsheet, database or analysis software.