Hello folks,
How can I count the switching cycles of a binary sensor?
Hello folks,
How can I count the switching cycles of a binary sensor?
With an automation using a State Trigger that increments a counter entity.
Or use a History Stats sensor to indicate the number of times the binary_sensor is on
during the current day (or other time period).
Okay thank you very much.
Is it also possible to display the measured data, for example in a bar chart or a mini-graph card?
So, I measure all switching cycles within a day and have the results for all days displayed in a diagram ā¦?
Now I tried it this way:
sensor:
- platform: history_stats
name: "Brennerstatistik Tag"
entity_id: binary_sensor.heizungsbrenner
state: "1"
type: time
start: "{{ now().replace(hour=0, minute=0) }}"
end: "{{ now().replace(hour=23, minute=59) }}"
- platform: history_stats
name: "Brennerstatistik Jahr"
entity_id: sensor.brennerstatistik_tag
state: "1"
type: time
start: "{{ now().replace(month=1, day=1, hour=0, minute=0, second=0) }}"
end: "{{ now().replace(month=12, day=31, hour=23, minute=59, second=0) }}"
binary_sensor:
- platform: mqtt
name: "Heizungsbrenner"
unique_id: "heatronic_brenner"
state_topic: "home/heizung/brenner"
payload_on: "1"
payload_off: "0"
I am curious if it works
It dosenāt work.
What am I doing wrong?
I saw it allready.
how can I put all the daily counted values into a chart?
It seems the history_stats sensor is the wrong way
The History Stats sensor can be used to report the daily count (and then it resets to start counting for the next day). What you want is to preserve each dayās total count so that you can show weekly/monthly/yearly information (in a graph). To do that, use the History Stats sensor in combination with the Utility Meter integration.
Thatās what I do to record the total amount of time my heating (and cooling) system operates throughout the year.
You can use the History Chart card to display a graph (and thereās a more sophisticated charting solution called ApexCharts).
Many thanks, but Iām afraid, that I donāt know how tu use the Utility Meter Integration to solve my problem.
Are you sure, that this is the right tool to compare all daily measurements (amount at 23:59)
Try this, let it run for a few days, decide if itās doing what you want.
utility_meter:
burner_daily:
source: sensor.brennerstatistik_tag
cycle: daily
burner_weekly:
source: sensor.brennerstatistik_tag
cycle: weekly
burner_monthly:
source: sensor.brennerstatistik_tag
cycle: monthly
burner_yearly:
source: sensor.brennerstatistik_tag
cycle: yearly
If you choose to change the sensor names to German, make sure the first one (sensor.burner_daily
) is not named exactly the same as the existing History Stats sensor (sensor.brennerstatistik_tag
).
Thank you, Iāll try
Hi, itās me again
Is there a way to count the off-states of a binary_sensor an reset it to zero, when the state is ON
tanks for help
I donāt understand your question.
I get a MQTT-signal every minute.
I want to count this signal when it has the value ā0ā
When the counter ist 15 I want to trigger an automation
When the signal has a value ā1ā, the counter should reset.
An MQTT Binary Sensor does nothing if the received value is the same as its current value.
If an MQTT Binary Sensorās state
is 1
and then it receives a 0
followed by another 0
and then another 0
, only the initial 0
causes a state-change from 1
to 0
and thatās what the History Stats sensor would count (if itās configured to count zeros).
Okay, and how can I solve my problem?
It is an additional problemā¦
Here are all of the MQTT-based integrations.
The one that might be best for your application is MQTT Device Trigger. However it might be challenging to make it usable with the 1
and 0
payloads you are receiving. Anyway, I suggest you explore that one.
itās easy,follow tips below:
1ćadd code to your configuration.yaml
sensor:
- platform: template
sensors:
switches_on_count:
friendly_name: "å·²ęå¼ēå¼å
³ę°éē»č®”"
value_template: "{{ states.switch | selectattr('state', 'eq', 'on') | list | count }}"
2ćadd a card
views:
- title: "Home"
cards:
- type: entities
entities:
- sensor.switches_on_count