Integrating with HomeAssistant

Hello, has anybody got an idiots guide on how to do this? I have been running Emonpi and EmonEVSE for charging car from solar for a while now. I have now had a try with HA and struggling a bit. I would like to send data from emonpi to HA so that I can turn plugs on etc to use excess solar instead of exporting. Any help would be appreciated Thank you.

The old topic was solved so start a new thread.

What have your tried and what doesn’t work?

I use the Emoncms integration for HA, it works well

This is my simple HA setup, photo was taken a while back when electricity prices were crazy cheap!

I have tried the above and keep getting error message in yaml (bad indentation of a mapping entry at line 26, column 3:
platform: emoncms)
I am new to HA and have been trying to get different things working and have got a bit lost. So now trying to get one thing at a time working.

Mark, getting the identation correct in YAML can be a pain, I use Visual Studio code when I work with YAML in HA as I find it is easier to see incorrect indentation which, if I recall correctly, indentation has to be spaces not tabs. It looks like I am about to embark on a similar path once I understand the Emoncms feed.

This is an excerpt from my Home Assistant config YAML where I pull a bunch of feeds into HA entities.

  - platform: emoncms
    api_key: xxxxxxxxxxxxxxxxxxxxxxxx
    url: https://emoncms.org
    scan_interval: 10
    id: 1
    unit_of_measurement: "W"
    value_template: '{{ value| round(0) }}'
    include_only_feed_id:
      - 374689 # import
      - 374691 # solar
      - 374693 # use
      - 405881 # export
    sensor_names:
      374689: "Importing"
      374691: "Generating"
      374693: "Using"
      405881: "Exporting"
3 Likes

This is all I put into my configuration.yaml, it just brings everything across from my emonPi which is on the same network. Note you have to use the IP address, you can’t use http://emonpi.

sensor:
  platform: emoncms
  api_key: xxxxxxxxxxxxxxxxxxxxxxxx
  url: http://192.168.1.201/
  id: 1

I think @Zarch probably has a more efficient solution, just choosing the feeds that are needed. I have 95 and didn’t really know which ones I wanted in HA.

1 Like

Thank you all, for help and suggestion’s. Still struggling, Going to try a clean install of HA and start again from scratch…

I’m using the same(ish) setup as @christian for the same reasons… :-

  platform: emoncms
  api_key: !secret emoncms_api_key
  url: http://192.168.20.20/emoncms
  id: 1

Studio Coder Server throws a wobbly saying “Incorrect type. Expected “array”” but it all seems to work.

If it’s still an issue after the rebuild let us know the errors you are getting.

This is the complete configuration.yaml that I use:

sensor:
  - platform: emoncms
    url: http://localhost/emoncms
    id: 1
    api_key: !secret emoncms

I put the API key in secrets.yaml so I never have to worry about editing the yaml if I’m pasting it online. I also run HA on my emonpi, so it just point it at localhost, but your setup is clearly different and I think you will need to give us a bit more detail so that we can help you.

Details from the log file, as well as which versions you’re running and where, will also be helpful.

Got it working eventually, my fault i have setup nest wifi network which my emonpi and ev are connected to. When i setup HA i plugged into back of router, so was on a different network. When all on same network took a bit of messing about but working ok now. Just got to learn next bit now. Think i have learnt a lesson? Thank you to all that have helped. I am learning slowly.

2 Likes

Hi

I am a new user at both HA and emoncms. I have successfully set up the EMONCMS HISTORY integration, but have not succeeded with the EMONCMS integration.

I am using the hosted service at emoncms.org

I use the simple code referenced and shown below.

sensor:
  - platform: emoncms
    api_key: MY ACCOUNT "Read & Write API Key"
    url: https://emoncms.org
    id: 1  

Q1: Am I using the correct key, the Read & Write API Key shown when I click on my account in emoncms?

Q2: for id, do I just use any random # not used anywhere on emoncms and or HA? What are the parameters of what # to/not to use?

I see an error in the HA log as follows. I have tried to find the referenced file but can’t see it.

Logger: homeassistant.components.sensor
Source: components/emoncms/sensor.py:194
Integration: Sensor (documentation, issues)
First occurred: 6:28:57 PM (1 occurrences)
Last logged: 6:28:57 PM

Error while setting up emoncms platform for sensor
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 353, in _async_setup_platform
    await asyncio.shield(task)
  File "/usr/local/lib/python3.11/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/emoncms/sensor.py", line 125, in setup_platform
    EmonCmsSensor(
  File "/usr/src/homeassistant/homeassistant/components/emoncms/sensor.py", line 194, in __init__
    elif elem["value"] is not None:
         ~~~~^^^^^^^^^
KeyError: 'value'

Also: I am looking in Settings → Sevices and Entities in HA to look for the new sensor. What will it be called and is that where i should look?

Do you have any suggestions? Is this still working for others?

Thanks!

1 Like

Hi. here is a brief update on this problem:

if in the home assistant yaml I add specific devices, rather than leave that portion blank so that all devices will be added, this is working. Do others have this constraint or is it unusual I need to list the specific devices in order for this to work?

Thanks

Yes. It is an issue with the component that I do not know how to fix :frowning:. Pretty sure there is an Issue open on it in HA.

Can anyone suggest anything? I added the emoncms integration code to the configuration.yaml file, everything worked fine for weeks, suddenly the integration failed with no data (perhaps after a power cut). Ive deleted the integration and added it again, changed the api key but i still cant get it to work again! Im a new HA user but think everything is otherwise ok.
addendum: and checked the IP address of the emonpi on the router too

integration
Thanks Mark

Anything in the HA log?

So this is where Im going to show my HA ignorance, do you mean the logbook in the left hand menu or is there a file I can look using the file editor? Thanks

No that is the logbook that records events.

You want Settings → System → Logs

Thanks Brian, got it. I cant see anything related to emonpi, but there are several other integrations im having issues with too :slight_smile:
home-assistant_2023-09-27T14-23-34.697Z.log.txt (10.0 KB)

It will be related to this error probably

[homeassistant.util.yaml.loader] YAML file /config/configuration.yaml contains duplicate key "sensor". Check lines 16 and 39

Did you check the YAML?

Developer tools →

image