Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
This repository was archived by the owner on Dec 7, 2021. It is now read-only.
/ha-history-statsPublic archive

📈 Statistics about your Home Assistant history

NotificationsYou must be signed in to change notification settings

bokub/ha-history-stats

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 
 
 

Repository files navigation

A home-assistant component that gives statistics about your history.

To try this component, justadd history_stats.py in.homeassistant/custom_components/sensor/ and restart home-assistant

N.B: This component is nowpart of the home-assistant core (introduced in version 0.39)


Thehistory_stats sensor platform provides quick statistics about another component or platforms, using data from thehistory.

It can track how long the component has been in a specific state, in a custom time period.

Examples of what you can track:

  • How long you were at home this week
  • How long the lights were ON yesterday
  • How long you watched TV today

Configuration

To enable the history statistics sensor, add the following lines to yourconfiguration.yaml:

# Example configuration.yaml entrysensor:  -platform:history_statsname:Lamp ON todayentity_id:light.my_lampstate:'on'type:timestart:'{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}'end:'{{ now() }}'

Configuration variables:

  • entity_id (Required): The entity you want to track
  • state (Required): The state you want to track
  • name (Optional): Name displayed on the frontend
  • type (Optional): The type of sensor:time,ratio, orcount. Defaults totime
  • start: When to start the measure (timestamp or datetime).
  • end: When to stop the measure (timestamp or datetime)
  • duration: Duration of the measure (seconds)

You have to provideexactly 2 ofstart,end andduration.

You can usetemplate extensions such asnow() oras_timestamp() to handle dynamic dates, as shown in the examples below.

Sensor type

Depending on the sensor type you choose, thehistory_stats component can show different values:

  • time: The default value, which is the tracked time, in hours
  • ratio: The tracked time divided by the length of your period, as a percentage
  • count: How many times the component you track was changed to the state you track

Time periods

Thehistory_stats component will execute a measure within a precise time period. You should always provide 2 of the following :

  • When the period starts (start variable)
  • When the period ends (end variable)
  • How long is the period (duration variable)

Asstart andend variables can be either datetimes or timestamps, you can configure almost any period you want.

Don't forget thatduration is a number of seconds, not a datetime. It is recommended to use it only if your period has a fixed length (24 hours, or 7 days, for example).

Examples

Here are some examples of periods you could work with, and what to write in yourconfiguration.yaml:

Today: starts at 00:00 of the current day and ends right now.

start:'{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}'end:'{{ now() }}'

Yesterday: ends today at 00:00, lasts 24 hours.

end:'{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}'duration:'{{ 24 * 3600 }}'

This morning (6AM - 11AM): starts today at 6, lasts 5 hours.

start:'{{ now().replace(hour=6).replace(minute=0).replace(second=0) }}'duration:'{{ 5 * 3600 }}'

Current week: starts last Monday at 00:00, ends right now.

Here, last Monday istoday as a timestamp, minus 86400 times the current weekday (86400 is the number of seconds in one day, the weekday is 0 on Monday, 6 on Sunday).

start:'{{ as_timestamp( now().replace(hour=0).replace(minute=0).replace(second=0) ) - now().weekday() * 86400 }}'end:'{{ now() }}'

Last 30 days: ends today at 00:00, lasts 30 days. Easy one.

end:'{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}'duration:'{{ 30 * 24 * 3600 }}'

All your history starts at timestamp = 0, and ends right now.

start:'{{ 0 }}'end:'{{ now() }}'

The/dev-template page of your home-assistant UI can help you check if the values forstart,end orduration are correct.


[8]ページ先頭

©2009-2025 Movatter.jp