Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Home Assistant auto discovery not picked up #31

Open
svh1985 opened this issue Jul 5, 2021 · 12 comments
Open

Home Assistant auto discovery not picked up #31

svh1985 opened this issue Jul 5, 2021 · 12 comments

Comments

@svh1985
Copy link

svh1985 commented Jul 5, 2021

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:[email protected]:1883
      - SMARTMETER_mqtt-discovery=true
      - SMARTMETER_debug=true
@svrooij
Copy link
Owner

svrooij commented Jul 5, 2021

@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
Copy link
Owner

svrooij commented Jul 6, 2021

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
Copy link
Author

svh1985 commented Jul 6, 2021

I would like build a dashboard that includes this information:

  • Current usage
  • Which Tarif (day or night)
  • Total day usage & Total night usage
  • Maybe optionally overall total usage

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

@svrooij svrooij closed this as completed in d35eb6d Jul 6, 2021
@svrooij svrooij reopened this Jul 6, 2021
@github-actions
Copy link

github-actions bot commented Jul 6, 2021

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

The release is available on:

Your semantic-release bot 📦🚀

@svrooij
Copy link
Owner

svrooij commented Jul 6, 2021

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
Copy link

@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
Copy link
Owner

svrooij commented Jul 7, 2021

@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?
d35eb6d#diff-3a9eff3aa76cd9e481d818b422f653ebf166101cc97a5842b684c1caaf555128L104-L118

The object is converted to json before sending to mqtt.

@svh1985
Copy link
Author

svh1985 commented Jul 8, 2021

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

HA
image

MQTT
image

@emontnemery
Copy link

emontnemery commented Jul 8, 2021

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

  • If you set state_class to measurement for a certain sensor, that sensor will be included in Home Assistant's long term statistics, you probably want to do that for all the sensors.
  • For the sensors measuring total consumed and exported energy and gas you also need to set the last_reset_topic for them to be included in long term statistics. If the smartmeter energy consumption never resets, you can set the last_reset_topic to same as state_topic and also declare a last_reset_value_template which returns UNIX epoch 0: {{ "1970-01-01T00:00:00+00:00" }}

@svrooij
Copy link
Owner

svrooij commented Jul 8, 2021

@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
Copy link

timongrob commented Jan 5, 2023

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
Copy link

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 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants