CurrentCost Component for Home Assistant

This is my 2nd “Share your Projects” on this topic. I finally created a component for this.
It’s currently a custom component, but I’m hoping to get it converted into a native HA component once I’ve learnt all the PR and Test tricks.

Anyway, for those interested, you can find my custom component on my repo here:

Feedback welcome :wink:

4 Likes

Thanks. I’ve been looking at alternative ways to do this, and will give your custom component a shot.

Currently I pull the data from PVOutput, but have been investigating using an ESP8266 to sample the current clamps directly, or read from the EnvIR monitor via serial.

How are you handling the sampling rate of the CurrentCost. I think it sends values over serial every 3 or 6 seconds. Are you reaveraging it to something else?

That’s correct it sends data every ~6 sec. I have for now only extracted “live” data and no history
I’m still trying to figure out how to dynamically create multiple entities from one sensor integration.
I don’t average anything but you could use a statistics sensor to do this…
I’d rather let people decide if they want to average and how the want to do this rather than me forcing it on them…

I suspect because it is a sensor it is already recording the historical data though, at least if you have the recorder or history components enabled. Have you noticed the load on your home assistant server increasing with the high data frequency?

Potentially having it as a single entity with multiple attributes might be a cleaner way to do it anyway. The PVOutput integration works like that.

I’m not seeing any extra load on my server really…
But then I have had that sensor for a long time now, although the data used to come from mqtt via a separate script

1 Like

Newbie here, looking for things to do if/when I’m isolated with the dreaded CV. Just discovered the existence of Home Assistant which looks a useful project.

I’ve been running a Current Cost setup for some years, as I received the unit from my electricity company as a freebie. I used mine as an excuse to program in Python, producing a rolling graph and cost. If a newbie is entitle to post a link, you’ll get the drift.

So, what would this custom component aim to achieve ? Graph display ? Stats ? I use RRDtool in my graph production. Medium term, I’m looking at a “time of use” electrical tariff, so that will need extra sums.

Obviously I’ve got a lot of reading to do. It all looks fascinating and I’m watching here with interest.

The component gets the live data out of the currentcost device and sends it to HA.
HA by default will plot the last 24h worth of data, but you can expand this by sending your data to Grafana / influxDB:


You can then also use the value to see if something is happening. For example I have a “dumb” dehumidifier that’s connected to a smart plug and power monitor.
If the dehumidifier is on but power is 0, the tank is full -> send a notification to empty the tank.
Possibilities are limitless

1 Like

Looks good, even if I have to dump RRDtool for Grafana :pensive: Certainly interesting enough for me to invest in yet another R Pi (for Home Assistant). Thanks for sharing so much info and code, appreciated.

1 Like

I think you’ll find Grafana to be better than RRDtool. I know I did.

OK, I’ve got Home Assistant Supervised running on Raspian Buster; all simple stuff, I’m impressed. I added the Hive integration with the “custom_components” (working nicely); the CurrenCost component docs do not have an “s”; is that significant ?

The first added line of the CurrentCost configuration.yaml then has a hyphen, which produces errors. My newbie eye says there should be an earlier line, unindented by spaces, perhaps
power:
which would be an integration name (not that integration power exists). Clearly, I’m wrong somewhere :grimacing:

I suspect a problem for me is the Home Assistant terminology. Despite reading the glossary a couple of times, I’m not there yet. Still, no rush.

Good spot, I’ll update the git page. It should indeed have an s at the end

The code in configuiration.yaml should be under the sensor header

[EDIT]
Now fixed

I too have just got the CurrentCost custom integration working but had to ad a few lines that were not included in the configuration.yaml example. I’ve been using my equipment to upload Gas, Elec, solar and several individual items to the PVOutput website for about 8 years.
I’m loving the whole Home Assistant think and just keep adding more and more to it (it really is limitless)
Thanks loluk44 for creating the custom component its a great piece of work, if only I’d come across it a few days earlier I might not have bothered buying the RTLSDR USB stick I was going to use to try and extract the Current Cost data via the 433 frequency but I’d probably still have a play around with that at some point.
I have a question about the yaml setup, what is the [:-2] for? I thought it might be some sort of data correction as in reduce temp by 2 degrees or reduce power value by 2w but I changed the figure and it appeared to have no effect.
On the subject of data correction do you know how that could be integrated.
I’ve noticed that the temperature from the EnviR has always been a few degrees too high so how could I instruct the integration to subtract 2 degrees from the indicted value.
Thanks again for your good work, its very much appreciated

this removes the unit (ºC or W) to return only a number instead of a string

value_template: '{{ state_attr("sensor.current_cost", "Temperature")[:-3] | float -2 }}'

1 Like

Ah! Thank you

Well, golly gosh, it just worked :grinning: Impressed. Next I need to cogitate on exactly why sensor: did the deed.

For the record, and anyone reading this who is also running an R Pi and HA Supervised, the R Pi needs the serial port enabling and the serial console disabling, all done with sudo raspi-config.

Grafana/influxDB next, if my brain can take it. @lolouk44 , any pointers within your github work (at first trawl, I didn’t see any) ? Thanks again for your time taken.

This is sensor, it needs to be in the sensor: section
If you had no previous sensors, you would have had to add this section, if not just add below existing sensors.

If you follow the InfluxDB doc, you should understand how it’s setup.
I personally don’t want to track everything, as I’m only interested in tracking some values over a longer time.
Then follow this guide by the excellent @arsaboo

lolouk44, is it possible to use one of the entity id value templates to then create another sensor such as daily total, weekly total, rolling total etc.
Also in the days when Current Cost hosted a web service to upload the data collected using there equipment is was possible to display a meter reading for Gas & Elec (and water if you had one I think)
is it possible to extract some data then calibrate a figure to correspond with your meter reading.

Hi @xion2000,

I only have the Elec data so can’t test.
If you’re able to give me an extract of the data I can look into it.
Are you able to open an issue on my github please?
I’ll create a script to extract the data into a file…

The first question was relating to the Elec data.

I have 2 OptiSmart sensors (Elec & Solar) & 1 GaSmart sensor which thanks to your integration I can now pull data directly into HA via a 2nd EnviR unit (my original one is still connected to a pc and uploads to PVOutput).

How do I extract the data to send to you?

I’ve upload 2 questions to GitHub after creating an account. Cheers

Apologies, I mean to raise an issue on github for the additional data.
For your totals, you can use the statistics
Though I think there may be such data inside the currentcost already, I’ll investigate