# Emoncms Home Assistant

**URL:** <https://community.openenergymonitor.org/t/emoncms-home-assistant/1667>\
**Category:** Integrations\
**Tags:** homeassistant\
**Created:** [11 September 2016 12:04 UTC](https://community.openenergymonitor.org/t/emoncms-home-assistant/1667 "2016-09-11T12:04:47Z")\
**Posts on this page:** 20\
**Page:** 3

<div class="post-metadata">

**Author:** ![bwduncan](https://community.openenergymonitor.org/letter_avatar_proxy/v4/letter/b/d78d45/32.png) [@bwduncan](https://community.openenergymonitor.org/u/bwduncan)\
**Post date:** [27 November 2021 22:51 UTC](https://community.openenergymonitor.org/t/emoncms-home-assistant/1667/43 "2021-11-27T22:51:48Z")

</div>

Quite right. Given the similarity to the function (as opposed to the filter) it might make more sense when you come back to read it in 6 months to note that the argument is the _default_, not the value being converted, so I prefer to be more explicit.

---

<div class="post-metadata">

**Author:** ![Robert.Wall](https://community.openenergymonitor.org/user_avatar/community.openenergymonitor.org/robert.wall/32/38246_2.png) [@Robert.Wall](https://community.openenergymonitor.org/u/Robert.Wall)\
**Post date:** [28 November 2021 00:49 UTC](https://community.openenergymonitor.org/t/emoncms-home-assistant/1667/44 "2021-11-28T00:49:45Z")

</div>

> [@bwduncan](#):
>
> It looks like I can’t edit my post,

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

---

<div class="post-metadata">

**Author:** ![bwduncan](https://community.openenergymonitor.org/letter_avatar_proxy/v4/letter/b/d78d45/32.png) [@bwduncan](https://community.openenergymonitor.org/u/bwduncan)\
**Post date:** [28 November 2021 18:25 UTC](https://community.openenergymonitor.org/t/emoncms-home-assistant/1667/45 "2021-11-28T18:25:46Z")

</div>

> [@Robert.Wall](#):
>
> Do you mean no.28

Yes, but @borpin edited it for me.

---

<div class="post-metadata">

**Author:** ![haffle](https://community.openenergymonitor.org/letter_avatar_proxy/v4/letter/h/d07c76/32.png) [@haffle](https://community.openenergymonitor.org/u/haffle)\
**Post date:** [14 January 2022 19:58 UTC](https://community.openenergymonitor.org/t/emoncms-home-assistant/1667/46 "2022-01-14T19:58:30Z")

</div>

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 …

```auto
### 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

---

<div class="post-metadata">

**Author:** ![bwduncan](https://community.openenergymonitor.org/letter_avatar_proxy/v4/letter/b/d78d45/32.png) [@bwduncan](https://community.openenergymonitor.org/u/bwduncan)\
**Post date:** [14 January 2022 20:07 UTC](https://community.openenergymonitor.org/t/emoncms-home-assistant/1667/47 "2022-01-14T20:07:30Z")

</div>

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.:

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

```

There can only be one `sensor:` tag.

---

<div class="post-metadata">

**Author:** ![borpin](https://community.openenergymonitor.org/user_avatar/community.openenergymonitor.org/borpin/32/193_2.png) [@borpin](https://community.openenergymonitor.org/u/borpin)\
**Post date:** [15 January 2022 08:38 UTC](https://community.openenergymonitor.org/t/emoncms-home-assistant/1667/48 "2022-01-15T08:38:39Z")

</div>

Have you got the `include` in the main file?

```auto
sensor: !include sensor.yaml

```

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

> [@bwduncan](#):
>
> You’re missing the `sensor:` key.

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

> [@bwduncan](#):
>
> There can only be one `sensor:` tag.

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

> [@bwduncan](#):
>
> You should be using a secrets.yaml and `!secret key` tags

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 ☹

---

<div class="post-metadata">

**Author:** ![haffle](https://community.openenergymonitor.org/letter_avatar_proxy/v4/letter/h/d07c76/32.png) [@haffle](https://community.openenergymonitor.org/u/haffle)\
**Post date:** [15 January 2022 11:00 UTC](https://community.openenergymonitor.org/t/emoncms-home-assistant/1667/49 "2022-01-15T11:00:01Z")

</div>

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

```auto
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

```auto

# 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.

```auto
### 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<

```

---

<div class="post-metadata">

**Author:** ![bwduncan](https://community.openenergymonitor.org/letter_avatar_proxy/v4/letter/b/d78d45/32.png) [@bwduncan](https://community.openenergymonitor.org/u/bwduncan)\
**Post date:** [15 January 2022 11:29 UTC](https://community.openenergymonitor.org/t/emoncms-home-assistant/1667/50 "2022-01-15T11:29:54Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![bwduncan](https://community.openenergymonitor.org/letter_avatar_proxy/v4/letter/b/d78d45/32.png) [@bwduncan](https://community.openenergymonitor.org/u/bwduncan)\
**Post date:** [15 January 2022 11:30 UTC](https://community.openenergymonitor.org/t/emoncms-home-assistant/1667/51 "2022-01-15T11:30:55Z")

</div>

> [@borpin](#):
>
> 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

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.

---

<div class="post-metadata">

**Author:** ![haffle](https://community.openenergymonitor.org/letter_avatar_proxy/v4/letter/h/d07c76/32.png) [@haffle](https://community.openenergymonitor.org/u/haffle)\
**Post date:** [15 January 2022 11:58 UTC](https://community.openenergymonitor.org/t/emoncms-home-assistant/1667/52 "2022-01-15T11:58:40Z")

</div>

Does this help?

[2022-01-15 1152 configuration\_yaml.txt](https://community.openenergymonitor.org/uploads/short-url/6esX2VJRE1NSowSg3Rm9nXe20Xi.txt) (1.6 KB)

[2022-01-15 1202 sensor.txt](https://community.openenergymonitor.org/uploads/short-url/vyszUESyU25Tmk5GtydrF8jN4Jk.txt) (6.3 KB)

---

<div class="post-metadata">

**Author:** ![bwduncan](https://community.openenergymonitor.org/letter_avatar_proxy/v4/letter/b/d78d45/32.png) [@bwduncan](https://community.openenergymonitor.org/u/bwduncan)\
**Post date:** [15 January 2022 12:04 UTC](https://community.openenergymonitor.org/t/emoncms-home-assistant/1667/53 "2022-01-15T12:04:55Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![haffle](https://community.openenergymonitor.org/letter_avatar_proxy/v4/letter/h/d07c76/32.png) [@haffle](https://community.openenergymonitor.org/u/haffle)\
**Post date:** [15 January 2022 12:38 UTC](https://community.openenergymonitor.org/t/emoncms-home-assistant/1667/54 "2022-01-15T12:38:24Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![bwduncan](https://community.openenergymonitor.org/letter_avatar_proxy/v4/letter/b/d78d45/32.png) [@bwduncan](https://community.openenergymonitor.org/u/bwduncan)\
**Post date:** [15 January 2022 12:44 UTC](https://community.openenergymonitor.org/t/emoncms-home-assistant/1667/55 "2022-01-15T12:44:45Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![haffle](https://community.openenergymonitor.org/letter_avatar_proxy/v4/letter/h/d07c76/32.png) [@haffle](https://community.openenergymonitor.org/u/haffle)\
**Post date:** [15 January 2022 13:23 UTC](https://community.openenergymonitor.org/t/emoncms-home-assistant/1667/56 "2022-01-15T13:23:10Z")

</div>

`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.

```auto
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'

```

---

<div class="post-metadata">

**Author:** ![bwduncan](https://community.openenergymonitor.org/letter_avatar_proxy/v4/letter/b/d78d45/32.png) [@bwduncan](https://community.openenergymonitor.org/u/bwduncan)\
**Post date:** [15 January 2022 13:32 UTC](https://community.openenergymonitor.org/t/emoncms-home-assistant/1667/57 "2022-01-15T13:32:09Z")

</div>

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](https://community.home-assistant.io/t/troubles-setting-up-emoncms-local/56170)

What version of home assistant are you running?

---

<div class="post-metadata">

**Author:** ![bwduncan](https://community.openenergymonitor.org/letter_avatar_proxy/v4/letter/b/d78d45/32.png) [@bwduncan](https://community.openenergymonitor.org/u/bwduncan)\
**Post date:** [15 January 2022 13:34 UTC](https://community.openenergymonitor.org/t/emoncms-home-assistant/1667/58 "2022-01-15T13:34:56Z")

</div>

@borpin did we not fix this?

> [@Home Assistant - Error](https://community.openenergymonitor.org/t/home-assistant-error/14839/5):
>
> No bother, worth knowing and getting fixed. I have raised an Issue

---

<div class="post-metadata">

**Author:** ![bwduncan](https://community.openenergymonitor.org/letter_avatar_proxy/v4/letter/b/d78d45/32.png) [@bwduncan](https://community.openenergymonitor.org/u/bwduncan)\
**Post date:** [15 January 2022 13:54 UTC](https://community.openenergymonitor.org/t/emoncms-home-assistant/1667/59 "2022-01-15T13:54:17Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![haffle](https://community.openenergymonitor.org/letter_avatar_proxy/v4/letter/h/d07c76/32.png) [@haffle](https://community.openenergymonitor.org/u/haffle)\
**Post date:** [15 January 2022 13:58 UTC](https://community.openenergymonitor.org/t/emoncms-home-assistant/1667/60 "2022-01-15T13:58:21Z")

</div>

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! 😀

```auto
{"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},

```

---

<div class="post-metadata">

**Author:** ![haffle](https://community.openenergymonitor.org/letter_avatar_proxy/v4/letter/h/d07c76/32.png) [@haffle](https://community.openenergymonitor.org/u/haffle)\
**Post date:** [15 January 2022 14:20 UTC](https://community.openenergymonitor.org/t/emoncms-home-assistant/1667/61 "2022-01-15T14:20:34Z")

</div>

> [@bwduncan](#):
>
> What version of home assistant are you running?

core-2021.12.9  
supervisor-2021.12.2

Both are the latest / current.

---

<div class="post-metadata">

**Author:** ![borpin](https://community.openenergymonitor.org/user_avatar/community.openenergymonitor.org/borpin/32/193_2.png) [@borpin](https://community.openenergymonitor.org/u/borpin)\
**Post date:** [17 January 2022 07:11 UTC](https://community.openenergymonitor.org/t/emoncms-home-assistant/1667/62 "2022-01-17T07:11:25Z")

</div>

> [@bwduncan](#):
>
> @borpin did we not fix this?
> 
> > [@](#):
> >
> > No bother, worth knowing and getting fixed. I have raised an Issue

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

[Previous page](https://community.openenergymonitor.org/t/emoncms-home-assistant/1667.md?page=2)

[Next page](https://community.openenergymonitor.org/t/emoncms-home-assistant/1667.md?page=4)
