CurrentCost Component for Home Assistant

Sorry, I’m not grasping what you want me to post on GitHub.
Spell it out to me & I’ll happily post it (I’m a bit of a numpty at times!!)

@xion2000 Looking at the CurrentCost page for your GaSmart sensor, and age of the device design, is it designed for the non-smart meters ? Possibly it looks at the meter red winking light, or reed relay ?

I guess what we all want is an API to our energy supplier. Not that would give a gas kW, for which we would probably need a gas flow meter, downstream of the energy supplier meter, all installed by a Gas Safe contractor. :grin:

lol yes. The currentcost is actually a clamp that goes around the wire on one of the phases. I had this and wanted the data in HA (so I can convert an appliance into a smart one by knowing when it’s on since it’s using power)
I don’t know how/if we can capture the data from the smart meters yet.

Yes my Gas meter is dumb, the GaSmart sensor is activated by a magnet (I think) on the meter reading.

My Elec meter is a Smart Meter. The OptiSmart reads the pulse light, I do not use the current clamp type as I don’t think they are as accurate.

You are correct re accuracy. Your electricity meter will be carefully designed, manufactured, type tested, certified, routinely replaced. Every man and his dog can make a current clamp, install it any old how and generally abuse it.

But the humble current clamp provides more frequent data (Current Cost every 6 seconds) against the pulse value of 1 kWh which probably takes many minutes or hours depending on electrical load. So, this makes for prettier graphs, and is good enough for many purposes.

I see it all as a stop gap, until we generally have access to energy supplier APIs. Googles… at least one in the UK, so progress is being made.

I’ve uploaded a copy of my log to GitHub.

Thanks for the pointer to statistics which I’ve given a test, and yes it works as expected. Not exactly pretty, nor bespoke enough for my liking but then I’ve not got a grip on Grafana at the moment.

1 Like

Update !
I’ve updated the custom_component to support impulse meters

Thanks @xion2000 for your help with the troubleshooting

Thanks for this, effortless to get it up and running compared to how hard it was last time I tried.
However, I have 3 current clamps attached to the transmitter which is meant for 3 phase commercial supplies. Instead I use them for monitoring different circuits in the home.
It is ages since I had this running but when I used to access the current cost tranmitter from 433Mhz RTL-SDR it was just a text line with the three values plus a total that got sent out. Any idea how I can get access to these values from within your component please? I had a look in the state topics in Developer Tools but didn’t look hopeful.
Anyway great work.

I had a quick look in your sensor.py and found the bit where you add the 3 channels:

            try:
                wattsch1 = int(data['msg']['ch1']['watts'])
            except:
                wattsch1 = 0
                pass
            try:
                wattsch2 = int(data['msg']['ch2']['watts'])
            except:
                wattsch2 = 0
                pass
            try:
                wattsch3 = int(data['msg']['ch3']['watts'])
            except:
                wattsch3 = 0
                pass
            total_watts = wattsch1 + wattsch2 + wattsch3
            if appliance == 0:
                if total_watts != 0:
                    self._state = total_watts

The problem is I have no idea how to offer any changes to Python script. I don’t even know if I have to compile it? I would be really grateful if you could point me in the right direction. Happy to do the donkey work and test it all and update accordingly. Thanks.

Well I had a go at working out what went where and I think I have it. First Python I have ever written so may well be wrong. I added 3 lines only to extract the individual channels, by setting the attributes:

            try:
                wattsch1 = int(data['msg']['ch1']['watts'])
                self._attributes[f"Channel 1"] = f"{wattsch1} W"
            except:
                wattsch1 = 0
                pass
            try:
                wattsch2 = int(data['msg']['ch2']['watts'])
                self._attributes[f"Channel 2"] = f"{wattsch2} W"
            except:
                wattsch2 = 0
                pass
            try:
                wattsch3 = int(data['msg']['ch3']['watts'])
                self._attributes[f"Channel 3"] = f"{wattsch3} W"
            except:
                wattsch3 = 0
                pass

Then I just defined the sensors in HA:

- platform: template
  sensors:
    currentcost_temperature:
      entity_id: sensor.current_cost
      unit_of_measurement: '°C'
      value_template: '{{ state_attr("sensor.current_cost", "Temperature")[:-3] | float }}'
      friendly_name: CurrentCost Temperature
    currentcost_power_total:
      entity_id: sensor.current_cost
      unit_of_measurement: 'W'
      value_template: '{{ state_attr("sensor.current_cost", "Appliance 0")[:-2] | int }}'
      friendly_name: CurrentCost Power Total
    currentcost_power_1:
      entity_id: sensor.current_cost
      unit_of_measurement: 'W'
      value_template: '{{ state_attr("sensor.current_cost", "Channel 1")[:-2] | int }}'
      friendly_name: CurrentCost Power 1
    currentcost_power_2:
      entity_id: sensor.current_cost
      unit_of_measurement: 'W'
      value_template: '{{ state_attr("sensor.current_cost", "Channel 2")[:-2] | int }}'
      friendly_name: CurrentCost Power 2
    currentcost_power_3:
      entity_id: sensor.current_cost
      unit_of_measurement: 'W'
      value_template: '{{ state_attr("sensor.current_cost", "Channel 3")[:-2] | int }}'
      friendly_name: CurrentCost Power 3

It all seems to work nicely and the 3 channels add up to the total. If anything is wrong please let me know.

Thanks for your feedback.
The change you made works in your case because you don’t have other appliances connected.
I’ve amended the code to return the channels reading only when reading from appliance 0 (total and supposedly the only device with more than 1 channel)

Thanks for the quick update. Just added your new sensor.yaml file. The power figures are displayed correctly except for a channel with no power consumption which displays as unknown. Is there a way to leave that at zero when no power is flowing?
Also can you pass the totals and costs through the code as well? Rather than doing all the adding up in HA it would be nice to put the night/day use and use over last 1/3/7 days straight to a glance card as well.

If a channel has no consumption, then it doesn’t show up indeed.
try and replace the if block on line 123 - 131 with this:

            if appliance == 0:
                self._state = total_watts
                self._attributes[f"Channel 1"] = f"{wattsch1} W"
                self._attributes[f"Channel 2"] = f"{wattsch2} W"
                self._attributes[f"Channel 3"] = f"{wattsch3} W"

For the totals / costs, I’ve not done this (yet) because the way current cost returns the data is a bit of a pain in the a$$ to compute, especially if you have several years of data like I do.
I might look at it at some stage…

Has anyone had any issues where the component stops communicating with the Currentcost unit? Mine randomly stops grabbing data from the Currentcost, initially I thought it was an issue with the serial port but it doesnt always drop all the appliances.

My setup is HASSIO running on a VM, the Currentcost has 2 transmitters, 1 for usage and 1 for solar generation.

When the component fails, I might lose both appliances or only one, nothing shows up in the logs, restarting the currentcost unit doesnt fix the issue. The only fix is to restart Home Assistant.

Any help would be appreciated.

Thanks

Can you set your currentcost logging level to debug?

logger:
  default: error
  logs:
    custom_components.currentcost: debug

Bear in mind it’s going to flood your logs, so don’t keep it on debug forevever

What do you mean by that? Do other appliances keep updating? Is it always the same appliances that stop updating?

Yes I’ve had issues with the component updating.
Won’t work longer than 24 hours.
Reboot of HA has it back working again.
I switched debug logging on for the component as suggested by lolouk44 and it was still running after 48 hours.
Turned debugging off and within 24 hours it had stopped again.
Nothing of interest in the logs.

so switching log level to debug keeps the component running? :thinking:

That is what I found.
I switched on debug hoping to spot something in the log as you suggested and gave up after a couple of days as it was still running fine.
Before that I kept restarting HA about once a day when I spotted it had stopped.
I decided to stop the logging and within a day it had stopped again.
Weird.

I’d setup the component and was trying to check the values against my actual electricity meter.
So at midnight I’d snap a pic of the meter and was trying to do the same after 24 hours.
But the component would die in the meantime.