Boiler Daily Burn Time Histogram wanted

I created a 8266 module that I put in my oil fired boiler. It reports cabinet, outflow and return temperatures, along with a room thermostat demand signal and a boiler water temperature demand signal. Ie, when the latter is on, the boiler is burning and using oil. It reports all this via mqtt to HA and I can graph it in Grafana.

My question here is that I want to find out and graph as a vertical histogram the daily/weekly/monthly burn time. Also, I would like it to be able to report to me somehow the burn time since last oil tank refill but I’m not sure of how to do any of this. I’ve not done any HA scripting, but have some knowledge of Node Red. Someone suggested History Stats but i don’t think that cuts it.

The YAML entry for the Entity I want to log is:

binary sensor:
  - platform: mqtt
    name: "Boiler thermostat demand"
    state_topic: "tele/boiler"
    value_template: "{{value_json['Therm']}}"
    payload_on: "On"
    payload_off: "Off"
    force_update: true

Any pointers to get me going would be appreciated.

The history stats sensor will only give you results for as long as your recorder purge_keep_days is set (default = 10 days). So while it would be fine for daily and weekly use, monthly could be a problem unless you are prepared to keep three times as much data in your recorder database. Have a look at the size of the database now. This may or may not be an issue for you.

Anyway to get the daily sensor:

sensor:
  - platform: history_stats
    name: Daily Boiler Demand
    entity_id: binary_sensor.boiler_thermostat_demand
    state: "on"
    type: time
    start: "{{ now().replace(hour=0, minute=0, second=0) }}"
    duration:
      hours: 24

You can then use Grafana’s “Group By” to get 7 and 30 day totals for your bar charts.

Unfortunately Grafana still has no method of grouping by month (though this is an often requested feature).

You may be able to feed the daily demand history stats sensor to a utility meter with weekly and monthly cycles. Not sure what format the history stats sensor will produce though. If it is seconds then it should work.

1 Like

That was quick Tom, thanks.

I tried something like that yesterday, my YAML entry was very similar (I also included one to count how many times it fired up):

sensor:
  - platform: history_stats
    name: Burn Time by Day
    entity_id: binary_sensor.boiler_thermostat_demand
    state: "On"
    type: time
    start: "{{ now().replace(hour=0, minute=0, second=0) }}"
    end: "{{ now() }}"
  - platform: history_stats
    name: Burn Count by Day
    entity_id: binary_sensor.boiler_thermostat_demand
    state: "On"
    type: count
    start: "{{ now().replace(hour=0, minute=0, second=0) }}"
    end: "{{ now() }}"

However, when I look at the Entities it creates and select the graph, it’s just a flat line at zero!

state: "On"

is not the same as

state: "on"

Binary sensor states are always 'on' or 'off' no matter how Lovelace chooses to display them.

Thanks, i did wonder but hadn’t tried it. Re-starting HA every time I edit the config file always freaks me out.

I’ve made the change and it’s now showing a count of 21 and time of 1.47 hours.

I’ll wait till tomorrow to see if logs each day gone by, and then a few more days before doing the grouping stuff in grafana and checking how much history I’ve got.

I do something similar, and I think you’re on the right track. I wrote it up here. I track thermostat demand (3 of them) and boiler burner run-time, which gives me a very accurate way to calculate fuel oil used over time.

@tom_I helped me get started with that project three years ago too. Just wanted to give a shout-out and thanks again for such consistent support to new users!

In my case I really couldn’t use the built-in Recorder database for all this long-term data. I take the current and previous days’ run times, and oil burn, then save those data in text files, one line per day. HA is a great tool for what it does, but it’s not where I want to do my long-term analysis.

1 Like

Tom Thanks for that. There’s a lot there to digest so it’ll keep me busy for a week or 2. Currently, I’m struggling with Grafana to get a vertical histogram! Just so many different areas you need to be knowledgeable in in this game.

I didn’t use reed switch but a mains sensor opto isolator. Initially tried a capacitative 3 transistors in-line amplifier circuit but found that once mains was in the boiler (demand) it would set it off, not just the pick-up on the thermostat output.

Wow, that’s a great graph!

[off topic] given the lag from thermostat partial-calling (upward slope) to full-demand and subsequent output; have you considered a “trend sensor”? I like using them to prematurely trigger a “full demand call” to things based on the upward slope in order to minimize the time between demand and output.

crlogic Not sure what a “trend sensor” is.

In any event, I think the upward slope when the heating demand or boiler thermostat demand comes on is an artifact of my clumsy setting up of the Grafana panel. I’ve actually programmed my 8266 to send 2 messages on each state change separated by 1s, one low and one high (or vice-versa). so I know the raw data is square.
I did that about a year ago now but the latest Grafana looks to be able to get round that, so I’m looking into it.

Ah, gotcha.

Sorted it. I had a mean(“value”) in the query so I think it was averaging. Just changed it to distinct(“value”). Seems to work but still might not be the best.

I ended up moving away from the door sensor and now have the burner and zone controller hooked up to relays (contactors) which directly feed GPIO pins on the RPi. I’ll have to change again when HA abandons support for GPIO pins. I’ve already got an ESP8266 ready to take over, much as I’d rather stick with just the one device. You’re lucky you chose the opto-isolator route.