Emoncms Home Assistant

Do you mean no.28? Change to:
state: "{{ states('sensor.emoncms_import_kwh') | float(default=none) | round(3) }}"

Yes, but @borpin edited it for me.

I used to have my emonCMS data working in HA, but after a nuke 'n re-install of Home Assistant it no longer works.

This time, in order to try & keep my config.yaml file a bit cleaner & tidier I have added a file called sensor.yaml . In there I have added …

### emonCMS #################################
  - platform: emoncms
    api_key: >>MY_EMONCMS_READ_API<<
    url: http://192.168.2.50/emoncms
    id: 1
    unit_of_measurement: "W"

This is exactly the same code as I used previously, albeit in a different file. But it doesn’t produce any devices or entities within HA.

Does anyone know if emonCMS works when a sensor.yaml file is included? (I need to keep it this way due to a load of other sensors that I have moved out of my config.yaml file & they work fine.)

TIA

You’re missing the sensor: key. Can you post your whole sensors.yaml file and configuration.yaml files? You should be using a secrets.yaml and !secret key tags to there should be nothing secret in either of these files, e.g.:

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

There can only be one sensor: tag.

1 Like

Have you got the include in the main file?

sensor: !include sensor.yaml

You should also not have any spaces before the - platform: statement in the sensor.yaml file.

Not if it is a sensor file - that is in the main file as an include.

Yes, but you can have all of the sensor definitions/config in a second file.

I’ve never got around to this as I don’t share my config anywhere and it is not as if the secrets file is encrypted.

[edit]
If I could find someone with a bit more knowledge that me of HA and Python, I’d add in a UI Config for the integration :frowning:

1 Like

Thanks both; my understanding (& it is just that, plus a bit of experimenting) is that if you have a line …

sensor: !include sensor.yaml

… in your config.yaml file (as I do), then you can’t put the text that @bwduncan showed above (presumably because the two conflict with each other?).

I have just hashed out the line sensor: !include sensor.yaml, and put the code in my config.yaml file instead, but whilst the Check Configuration comes back as Valid, still no devices or entities appear. I also lose all of the other sensors that were working within my sensor.yaml file, so have reversed this change for now.

This is the start of my config.yaml file


# Configure a default setup of Home Assistant (frontend, api, etc)
default_config:

# Text to speech
tts:
  - platform: google_translate

group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
### 2022-01-04: Sensors are in a seperate yaml file ###
sensor: !include sensor.yaml
camera: !include ffmpeg.yaml


And this is the start of my sensor.yaml file. NB: I will sort the !secret bit out later - I like to try to keep things simple initially when problem solving.

### sensor:
### 2022-01-04: This file was created to help tidy up the main config.yaml file #######################

### emonCMS #####################################
  - platform: emoncms
    api_key: 79_REDACTED_35
###    api_key: !secret emoncms_api
    url: http://192.168.2.50/emoncms
    id: 1
    unit_of_measurement: "W"
    
### OIL TANK SENSOR ##############################
### Time Stamp ######
  - platform: mqtt
    name: "Oil Last Time Stamp"
    state_topic: "home/rtl_433"

>SNIP<

Please can you do the secrets thing and just upload your configs as attachments or upload to a pastebin? I have a feeling that this is a really simple problem but it’s being hidden but the snips, redaction and cutting off the ends of files.

The platform configs in HA are pretty advanced. I tried to learn some of the new bits for another integration and got so lost, but I’ll try to find some time to learn it again and get back to you.

Does this help?

2022-01-15 1152 configuration_yaml.txt (1.6 KB)

2022-01-15 1202 sensor.txt (6.3 KB)

Yes thanks, it looks like your sensors.yaml has spaces at the start of each line. Can you de-indent the whole file and try again?

I have done that (& rebooted), but whilst HA still “works”, no emonCMS devices or entities show up.

emoncms should know the units of each sensor. Can you try removing the unit_of_measurement key from sensors.yaml?

I presume you have checked that you can access that url from the HA machine? I presume there are no helpful errors in the log file? It might be worth turning on debugging to see what the problem is.

unit of measurement line is removed, but no change. I run HA on a headless Intel NUC so can’t easily check comms, but from within HA’s Terminal ping 192.168.2.50 works OK.

If I log in to my emonPi via 192.168.2.50, after the username/password prompt I can see the Feeds updating normally (ie in green).

Quick question: does using 192.168.2.50/emoncms, coupled with a read API get past the username/password dialogue box? Presumably it does…

EDITED TO ADD: This was in the Logs.

2022-01-15 13:14:43 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up emoncms platform for sensor
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 249, in _async_setup_platform
await asyncio.shield(task)
File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 52, in run
result = self.fn(*self.args, **self.kwargs)
File "/usr/src/homeassistant/homeassistant/components/emoncms/sensor.py", line 118, in setup_platform
EmonCmsSensor(
File "/usr/src/homeassistant/homeassistant/components/emoncms/sensor.py", line 170, in __init__
self._state = round(float(elem["value"]), DECIMALS)
TypeError: float() argument must be a string or a number, not 'NoneType'

Yes, the API key is an alternative authentication mechanism.

Nice ninja edit! Ah yes that’s a bug. You can work around it by removing the invalid data: Troubles setting up EMONCMS local - Configuration - Home Assistant Community

What version of home assistant are you running?

@borpin did we not fix this?

For anyone coming back to read this later, the solution is to remove the NULL feeds from emoncms.

2 Likes

I had one "value":null feed, and having excluded it with HA all now appears to be working. Thanks to all who have helped with this - much appreciated! :grinning:

{"id":"363","userid":"1","name":"timestamp","datatype":"1","tag":"vantageMqtt","public":"0","size":"","engine":"5","processList":"","unit":"","time":null,"value":null,"start_time":0,"interval":10},
1 Like

core-2021.12.9
supervisor-2021.12.2

Both are the latest / current.

No, I raised the issue, but didn’t get any help actually fixing it, and my Python is really not good enough to try :frowning:

I ran into this problem too after moving HA to new hardware (via backup/restore), while emonpi did not change. For some reason emoncms connection kep dieing and complaining about those max retries error. Reboots here and there brought it back for a little while and then ded again. But going to http://emonpi.local and logging in - the feeds and reporting was running no problem.
For me /emoncms was not an option because there’s nothing in that folder.
I’m not sure what network bs is/was the reason, because i did not change anything on router/emonpi side, but what helped was going from http://emonpi.local to http://ipaddress
Not the best solution but meh whatever, my emonpi ip is static lease in the router anyway.

Maybe helps someone else.