svrooij / smartmeter2mqtt

Publish data from your Smart meter with a P1 interface to you MQTT server.
http://smartmeter2mqtt.svrooij.io
MIT License
31 stars 9 forks source link

Home Assistant auto discovery not picked up #31

Open svh1985 opened 3 years ago

svh1985 commented 3 years ago

Hello,

I'm trying to connect the HA, but for some reason HA doesn't pick up the data using auto discovery. I'm not sure what I'm doing wrong. Do I need to add some additional config?

The MQTT messages are published, (filtered view of) MQTT structure:

image

Docker-Compose

  smartmeter:
    container_name: smartmeter
    image: svrooij/smartmeter:beta
    devices:
      - /dev/serial/by-id/usb-FTDI_FT232R_USB_UART_AQ4QV4S5-if00-port0:/dev/ttyUSB0
    restart: unless-stopped
    ports:
      - 3000:3000
      - 3010:3010
      - 3020:3020
    environment:
      - TZ=Europe/Amsterdam
      - SMARTMETER_PORT=/dev/ttyUSB0
      - SMARTMETER_web-server=3000
      - SMARTMETER_tcp-server=3010
      - SMARTMETER_raw-tcp-server=3020
      - SMARTMETER_mqtt-url=mqtt://user:pw@172.16.0.1:1883
      - SMARTMETER_mqtt-discovery=true
      - SMARTMETER_debug=true
svrooij commented 3 years ago

@svh1985 I'm no home assistant user, this auto discovery is build according to the specs (some time ago). Apparently they don't work.

How should the auto discovery messages be formatted? Did you turn on mqtt auto discovery in home assistant?

svrooij commented 3 years ago

I've just setup a home assistant instance just to test this. It seems the discovery message (which is exactly as documented) is not working. Changing them to the same format as zigbee2mqtt and they get picked up immediately.

What values would you like to see in home assistant?

svh1985 commented 3 years ago

I would like build a dashboard that includes this information:

Let me know if I can do something to help/test :)

github-actions[bot] commented 3 years ago

:tada: This issue has been resolved in version 1.7.0-beta.7 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

svrooij commented 3 years ago

Small sample:

image

@svh1985 you could test the latest beta and see if it works for you now, the docker version is currently building, see https://github.com/svrooij/smartmeter2mqtt/runs/3002295741 (usually takes +/- 14 minutes)

emontnemery commented 3 years ago

@svrooij

It seems the discovery message (which is exactly as documented) is not working. Changing them to the same format as zigbee2mqtt and they get picked up immediately.

Can you give some examples of what you tried which didn't work?

Documentation is here:

svrooij commented 3 years ago

@emontnemery I didn't see the second page when I implemented this a year ago. After this change the sensors started appearing. Do you need me to write out the config messages or can you see it in the changes? https://github.com/svrooij/smartmeter2mqtt/commit/d35eb6d4dd51823b1dd0eaf1c1380b242e4813f0#diff-3a9eff3aa76cd9e481d818b422f653ebf166101cc97a5842b684c1caaf555128L104-L118

The object is converted to json before sending to mqtt.

svh1985 commented 3 years ago

I downloaded the new beta and only the current Tarrif is picked up:

HA

image

MQTT

image
emontnemery commented 3 years ago

@svrooij The change makes substantial changes to the functionality though; you now tie the sensors to a device object in Home Assistant but you also remove the availability feature, which means the sensors will always appear as available in Home Assistant. If sensors are not tied to a device, they will show up as orphans under the MQTT integration as well as under entities but not be listed under devices. Before this change, what went wrong or didn't work as expected?

By the way:

svrooij commented 3 years ago

@emontnemery this didn't work. I need to mention, I myself am no home assistant user, so adding home assistant support is just for others to enjoy.

The sensors where not picked up (as stated by @svh1985 ), I then started a clean home assistant installation as a docker container in windows (which just works as opposed to the documentation saying not working). And connected it to my already being used mqtt server. The entities didn't show up. So I guess that can be called not working.

I then just tried to send out the same config file as zigbee2mqtt does.

I don't use this part myself, but want to help others, this (home assistant discovery) is included. If it needs changing please state what should be send instead of the current messages (this is de latest version that is building as we speak).

Power usage:

{
  "availability": [
    {
      "topic": "smartmeter/connected",
      "payload_available": "2"
    }
  ],
  "device": {
    "identifiers": [
      "smartmeter_xxx"
    ],
    "model": "KFM5KAIFA-METER",
    "name": "DSMR power 33137",
    "sw_version": "smartmeter2mqtt (0.0.0-development)"
  },
  "device_class": "power",
  "state_class": "measurement",
  "json_attributes_topic": "smartmeter/status/energy",
  "state_topic": "smartmeter/status/energy",
  "name": "Current power usage",
  "icon": "mdi:transmission-tower",
  "unit_of_measurement": "Watt",
  "value_template": "{{ value_json.calculatedUsage }}",
  "unique_id": "smartmeter_xxx_current-usage"
}

With these latest messages, the devices just show up, like here. 🎉

image

image

Starting home assistant in docker on windows docker run --init -d --name homeassistant -v /etc/localtime:/etc/localtime:ro -v /mnt/c/Users/my-username/.ha:/config -p 8123:8123 ghcr.io/home-assistant/home-assistant:stable

timongrob commented 1 year ago

Hi, was playing around with this one to see if I can use it to move from Domoticz to Home Assistant. Am running into the same issue when using the latest build and want to try the beta version but it gives "# Fatal error in , line 0". Would be great if you could help me with this.

Thanks!

timongrob commented 1 year ago

For those running into the same issue: I managed to get it work using smartmeter2mqtt-latest version by adding this to my configuration.yaml:

# template for Energy mqtt sensor
template:
  - sensor:
      - name: "Electricity Usage"
        unique_id: "DSMREU01"
        unit_of_measurement: "kWh"
        state: >
          {{ states("sensor.current_power_usage") | float(0) / 1000 }}
        device_class: energy
        state_class: total
      - name: "Electricity Usage T1"
        unique_id: "DSMRTU01"
        unit_of_measurement: "kWh"
        state: >
          {{ states("sensor.total_power_used_t1") | float(0) }}
        device_class: energy
        state_class: total_increasing 
      - name: "Electricity Usage T2"
        unique_id: "DSMRTU02"
        unit_of_measurement: "kWh"
        state: >
          {{ states("sensor.total_power_used_t2") | float(0) }}
        device_class: energy
        state_class: total_increasing
      - name: "Electricity Return T1"
        unique_id: "DSMRTR01"
        unit_of_measurement: "kWh"
        state: >
          {{ states("sensor.total_power_delivered_t1") | float(0) }}
        device_class: energy
        state_class: total 
      - name: "Electricity Return T2"
        unique_id: "DSMRTR02"
        unit_of_measurement: "kWh"
        state: >
          {{ states("sensor.total_power_delivered_t2") | float(0) }}
        device_class: energy
        state_class: total
      - name: "Gas Usage"
        unique_id: "DSMRGU01"
        unit_of_measurement: "m³"
        state: >
          {{ states("sensor.total_gas_usage") | float(0) }}
        device_class: gas
        state_class: total_increasing