Hi I am trying to start a project with HomeAssistant in our production, We just got a new Fiber Laser and I want to count the cutting time through the day, We have put in a Shelly Pro 2 that so every time the machine is cutting the Shelly states an ON, I have used History State to define how many cutting hours there have been in a normal working day, but I would like a Boolean template where I have the total cutting time, is there anyone that could help arrive this
Like:
- platform: history_stats
name: Time the line was cut today
entity_id: sensor.shelly2
state: "on"
type: count
start: "{{ now().replace(hour=0, minute=0, second=0) }}"
end: "{{ now() }}"
Replacing the count
with time
will give you the time it was on, and so on, read the documentation for additional help to compute week, month or more statistics.
EDIT: You can replace the start and end by the scheduling helper values.
Therefore, you can compute for the whole day or for the working period only
Tip:
For future reference, all of these produce the same time:
{{ now().replace(hour=0, minute=0, second=0, microsecond=0) }}
{{ today_at('00:00:00') }}
{{ today_at() }}
So if you need the time representing the beginning of the current day, today_at()
is the shorted way to get it.
You are right, but the now().replace(hour=0, minute=0, second=0, microsecond=0)
is what is used as example in the doc
Because the example in the documentation predates the introduction of the today_at
function.
After scouring all the seas of the community, maybe it’s time to update the docs, it’s our destiny!
The documentation is created/updated by volunteers (i.e. anyone who has the time to do it).
At the bottom of every documentation page is an Edit link. It leads to a GitHub repository containing the source code (Markdown language) of the page where (if you have a free GitHub account) you can log in and submit a Pull Request (PR) containing the changes you wish to have incorporated into the documentation. After submitting the PR, someone from the development team reviews it and, if it’s acceptable, merges it into the documentation.
I have the History State set up to show the 3 shift working on the machine.
What if I want the total cutting hour from the day it started and until know.
We setup the machine start December last year, so I want the total from there and to now, also I need to keep the total hour without it getting reset.
My plan is to make a dashboard on the machine showing how effective the machine has been on the different shift, showing last 24hours from 7:00-15:00, 15:00-00 and from 00:00 to 7:00.
And then the total hours at all.
Can I do it all with History State?
Hope you know what I mean and sorry if it sounds stupid.
Not sure to get everything you want but history state can help for the yesterday values for sure
sensor:
- platform: history_stats
name: yesterday 15:00-00:00
entity_id: sensor.shelly2pro
state: "on"
type: count
end: "{{ today_at() }}"
duration:
hours: 9
- platform: history_stats
name: yesterday 00:00-07:00
entity_id: sensor.shelly2pro
state: "on"
type: count
start: {{ as_timestamp( today_at() ) - 86400 }}
duration:
hours: 7
- platform: history_stats
name: yesterday 07:00-15:00
entity_id: sensor.shelly2pro
state: "on"
type: count
start: {{ as_timestamp( today_at()) - 61200 }}
duration:
hours: 8
- platform: history_stats
name: yesterday total
entity_id: sensor.shelly2pro
state: "on"
type: count
end: {{ today_at() }}
duration:
hours: 24
CAVEAT: This was not tested, I leave to you to test it with your configuration and shelly’s name