433mhz energysensor from foogadgets

I have an energysensor from foogadgets that communicates over 433.
The energysensor shows as an temp and humidity sensor.

Is there any chance to get this to work with for example appdaemon?

I got this from the foogadgets site:

if ( !signbit(temperature) ) {
i_counts = humidity4096 + (int)(10.0temperature);
} else {
i_counts = humidity4096 - (int)(10.0temperature) + 2048;
}

First get to know your energy meter recalculation factor. Find the [imp/kWh] marking on your energy meter. Then divide 1,000 with the number you find.

Example 1. If it is marked with 10,000imp/kWh the recalculation factor is 1,000/10,000 = 1/10
Example 2. If it is marked with 500imp/kWh the recalculation factor is 1,000/500 = 2

Once you have the recalculation factor you can use that to calculate the consumed Energy and present Power usage
Energy [kWh], multiply your received number with the recalculation factor for your energy meter. You will likely want it in [kWh], thus the dividend 1,000.

      Energy = count • (recalculation factor) / 1,000

Power usage [kW] you need to divide the difference in detected pulses with the elapsed time [s].

      Power = ∆ count • (recalculation factor) • 60 • 60 / ∆ t / 1,000

To get the consumtion of the day you take the last and the first “Energy” of the and subtract it

What I get the device is just a counter. So i guess to get the todays consumption you will need to subtract the last and the first input of the day and so on.

It seems that the have an plugin in Domoticz,

I hope you guys can help me out.

( I don’t know if I am in the right category)

How did you configure the device? You say it’s 433MHz, which bridge/dongle do you use to catch the 433MHz signal?

A skeleton on how to do it in appdaemon (assuming you have a counter defined). This hasn’t been tested (or even loaded) so it will have errors, but will get you started.

What you do with energy and power calculations is up to you. :grinning:


import appdaemon.appapi as appapi
import datetime

#
# App to calculate energy use

# Args
# recalculation_factor
# energy_counter_sensor

class EnergySensor(appapi.AppDaemon):


    def initialize(self):
        try:
            self.recalc_factor = int(self.args["recalculation_factor"])
            if self.entity_exists(self.args["energy_counter_sensor"])
                self.log("{} does not exist".format(self.args["energy_counter_sensor"]))
                return

            midnight = datetime.time(0, 0, 0)
            self.run_daily(self.midnight_cb, midgnight)
        except KeyError as e:
            self.log("Argument not found : {}".format(e), level="ERROR")
        except ValueError as e:
            self.log("recalculation_factor must be an int : {}".format(e), level="ERROR")

    def midnight_cb(self, kwargs):
        if self.previous_day_end:
            self.previous_day_start = self.previous_day_end
        self.previous_day_end = self.get_state(self.energy_counter_sensor)
        if self.previous_day_start:
            energy = calculate_energy(self.previous_day_start)
            power = calculate_power()

    def calculate_energy(self, energy_counter):
        return energy_counter * self.recalc_factor / 1000

    def calculate_power(self):
        seconds_in_day = 60 * 60 * 24
        return (self.previous_day_end - self.previous_day_start) * self.recalc_factor / seconds_in_day / 1000

I use Tellstick Net to get the data from the device.
And it show as an temp/hum sensor.
Here is mine, i changed the name to Watt.

Thank you gpbenton i will try this one out.
Im all new to appdaemon so its great to get a start.

I will let you know how it ends up :slight_smile:

I am trying to figure out how appdaemon works.
I have compiled the code now without any errors but i had to remove this line and som other stuff.

if self.entity_exists(self.args[“energy_counter_sensor”])

The args is added but still got error on that line.

How do return the energy and the power-value back to HA?

What was the error?

It depends a lot on what you intend to do with the information. The simplest would be to use set_state to set the state of a sensor, but you could also use call_service to send it to a service.

The error as follow:

2017-11-17 18:48:30.046600 WARNING Traceback (most recent call last):
  File "/var/opt/homeassistant/appdaemon/appdaemon/appdaemon.py", line 901, in read_app
    importlib.reload(conf.modules[module_name])
  File "/usr/lib/python3.4/importlib/__init__.py", line 149, in reload
    methods.exec(module)
  File "<frozen importlib._bootstrap>", line 1153, in exec
  File "<frozen importlib._bootstrap>", line 1129, in _exec
  File "<frozen importlib._bootstrap>", line 1467, in exec_module
  File "<frozen importlib._bootstrap>", line 1572, in get_code
  File "<frozen importlib._bootstrap>", line 1532, in source_to_code
  File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
  File "/var/opt/homeassistant/appdaemon/conf/apps/wattcount.py", line 18
    if self.entity_exists(self.args["energy_counter_sensor"])
                                                            ^
SyntaxError: invalid syntax

I want to show to total daily usage in a graph, and maybe todays total usage as a widget?
And i want to show the current usage as a widget.

So perhaps a sensor would work?

Is missing a colon at the end

    if self.entity_exists(self.args["energy_counter_sensor"]):

I said I hadn’t checked the code :slight_smile:

It sounds like a sensor would do for you. I don’t know anything about widgets though.

yeah I know :slight_smile:
I tried to go through the code but must have missed that one.
Maybe I have missed more, but only the time will tell :smiley:

Do I create a template-sensor and run the set_state to that sensor?

You just need a sensor that won’t update by any other means. I think you can create a template sensor to do that.

Alternatively, you can store it in an input_number by calling the input_number set_value service.

Or another way would be to write the data to a file, and read the data from the file with the file sensor. The advantage of this is that you would have the data available outside of HA, so you could use whatever graphing program you like to look at it.

Hi Kris!

I have the very same sensor and use the “command line sensor” with a small python script. That works pretty well since several months. The problem is that I can’t use Hass.io as I can not run any python scripts there as far as I know. If you want I can share the script with you by mail.

/Reik

I have the same sensor and would be so glad to get the script to try implementing it. I used to run Domoticz but changed to HA yesterday. Thanks!
//Rich

I would love to have your script.
Mine does not work that well.

Hi there!

I’m using a tmp file to store the values and 3 small python scripts for current, daily and monthly consumption. You will need TellCore to read the sensor:

TellCore

Don’t forget to install it in venv. Then you can find the scripts her:

Scripts

You need to figure out which ID your sensor has (mine is 70) and change it in the read_power.py.
Good luck and let me know if I can help!

/Reik

1 Like

The scripts-link does not work.

My bad!

Fixed!

Hi There!

As I switched to Hass IO I was forced to change the approach a little. It’s now a custom component which needs to be copied into your config folder.

custom_components.zip

It can be used like this:

In the sensors add:

  - platform: power

Then you can find:

  - sensor.power_consumption
  - sensor.power_consumption_daily
  - sensor.power_consumption_monthly

As before you need to change the SensorID = 70 in custom_components\sensor\power.py

BR

/Reik

1 Like

I’m on the usual Homeassistant in Virtual Environment. Can I use your new approach in HA? or do I need to use the older script files? The link seems to be dead “The requested URL /read_power.zip was not found on this server.”
Regards Richard

Yes! That should work as well. I removed the old version from the server as the new seems more usable. You might need to install TellCore if you have the normal HomeAssistant!

BR

/Reik