Andoramb / i2c_2_mqtt

Basic script to interact with I2C relays on a Raspberry Pi through MQTT
GNU General Public License v3.0
0 stars 0 forks source link

HomeAssistant discovery #2

Open HeneryH opened 2 months ago

HeneryH commented 2 months ago

Sorry for the "issue" submission.

Here is the log from the app

(.venv) me@pzw-1:~/i2c_2_mqtt $ python3 mqtt2i2c.py config.yaml
Sent HA switch discovery {"name": "pzw-1", "state_topic": "I2C/pzw-1/I2C/device_name/state/1", "command_topic": "I2C/pzw-1/I2C/device_name/cmnd/1", "payload_off ": "off", "payload_on": "on", "icon": "mdi:power", "availability": [{"topic": "I2C/pzw-1/I2C/device_name/state/availability"}]}

This is what I see coming from my pi running the i2c_2_mqtt app. The mosquito broker in HomeAssistant is logging this...

2024-07-06 11:57:01: New connection from 192.168.1.161:59093 on port 1883.
2024-07-06 11:57:01: New client connected from 192.168.1.161:59093 as auto-586A9955-875F-AF56-906D-80469CA56136 (p2, c1, k60, u'my_name').

192.168.1.161 is indeed the pi-zer-w that I am trying this on.

Here is my config

device_name: pzw-1
mqtt:
  broker: 192.168.1.96
  port: 1883
  username: my_user
  password: my_pw
  state_topic: 'I2C/device_name/state'
  command_topic: 'I2C/device_name/cmnd'
homeassistant:
  discovery: "true"
  discovery_prefix: homeassistant
i2c:
  device_address: 0x11
  register_address:
    1: 0x10

I am using a different relay board than you so the i2c commands are a little different. I can only bang a single register at 0x10 to turn relays on and off. Unfortunately no reading of current state.

Any ideas why the new device is not showing as discovered in my HA server? That HA/Mosquito log doesn't seem like what I was expecting.

Andoramb commented 1 month ago

Hi, sorry for the delay, I was offline :)

Let's try to change your config file to this:

device_name:  pzw-1
mqtt:
  broker: 192.168.1.96
  port: 1883
  username: my_user
  password: my_pw
  state_topic: state
  command_topic: cmnd
homeassistant:
  discovery: true
  discovery_prefix: homeassistant
i2c:
  device_address: 0x11
  register_address:
    1: 0x10