odig / eboxToMqtt

Using a ESP32 to grep data from E-BOX console port and send them to MQTT.
MIT License
4 stars 0 forks source link

MQTT in Home Assistant #2

Closed juanka99 closed 1 year ago

juanka99 commented 1 year ago

I have flashed the ESP32 and this is the captive portal: image

No sensors appairs in Home Assistant mqtt... What I have to do?

odig commented 1 year ago

Can you telnet to 192.168.1.223 from you computer? telnet 192.168.1.223 Put in "help" and get an answer?

Check if infos are written to MQTT. Use a tool like MQTTExplorer. If you connect to your MQTT server (192.168.1.82) you should see entries on top level named "pytes". There must be also a top level Entry named "homeassistant" for HA auto discovery.

image

In HA there must be the integration "MQTT" installed. This integration has an auto discovery feature which looks in "homeassistant" in MQTT.

odig commented 1 year ago
image
juanka99 commented 1 year ago

image

image

juanka99 commented 1 year ago

Is it mandatory to have the RS232 adapter connected for the mqtt connection to work? I only have the ESP32. I haven't received the RS232 adapter yet...

odig commented 1 year ago

Without an RS232 adapter you don't get entities but the error Message should not show up if MQTT server is available and properly configured.

Looks like your MQTT IP or USER or PASSWORD is not correct.

Normally Homeassitant IP and an Homeassistant User and his Password. And you have "Mosquito Broker" installed as an agent in Homeassistant.

juanka99 commented 1 year ago

Without an RS232 adapter you don't get entities but the error Message should not show up if MQTT server is available and properly configured.

Looks like your MQTT IP USER or PASSWORD is not correct.

Normally Homeassitant IP and an Homeassistant User and his Password. And you have "Mosquito Broker" installed as an agent in Homeassitant.

IP, USER and PASSWORD are correct. The same I use in MQTT Explorer:

image

odig commented 1 year ago

If MQTT explorer works, the ESP32 should also.

Double check user and pasword please.

Looks like all is on the same network (192.168.1.x). MQTT uses a normal TCP/IP connection on port 1883 on default. Can you ping/telnet the ESP32 from homeassistant console?

If you remove the comment from line 1 in src/main.cpp you enable SIMULATION and no serial is needed.

juanka99 commented 1 year ago

If MQTT explorer works, the ESP32 should also.

Double check user and pasword please.

Looks like all is on the same network (192.168.1.x). MQTT uses a normal TCP/IP connection on port 1883 on default. Can you ping/telnet the ESP32 from homeassistant console?

If you remove the comment from line 1 in src/main.cpp you enable SIMULATION and no serial is needed.

I have check 3 times user and password. And I ping the ESP32 from Homeassistant without problem:

image

juanka99 commented 1 year ago

Hi again,

My ESP32 is like this. Could be this the problem?

image

Or the mqttServer IP?

image

odig commented 1 year ago

You are right, I was totally out of my mind coding the mqttServer config.

Please adjust line 78 for now for your needs. I'll will fix the code these days.

juanka99 commented 1 year ago

You are right, I was totally out of my mind coding the mqttServer config.

Please adjust line 78 for now for your needs. I'll will fix the code these days.

Ok. I'll do it this afternoon when I get home. I'll let you know how the change has gone.

juanka99 commented 1 year ago

You are right, I was totally out of my mind coding the mqttServer config.

Please adjust line 78 for now for your needs. I'll will fix the code these days.

I adjust line 78 with IPAddress mqttServer(192, 168, 1, 82); and all it´s same. It doesn´t work

image

juanka99 commented 1 year ago

Is there anything else I have to edit to make it work?

I'm about to give up :-(

odig commented 1 year ago

Please change line 766 to your user and password. As i said forgot to use the configured values for MQTT. Sorry.

Otherwise there should be time on weekend to fix and debug it myself.

juanka99 commented 1 year ago

Please change line 766 to your user and password. As i said forgot to use the configured values for MQTT. Sorry.

Otherwise there should be time on weekend to fix and debug it myself.

Line changed and now this is MQTT Explorer test:

image

odig commented 1 year ago

MQTT is now connected. :-)

If you wanna see simulated data as long you have no serial connected remove the "//" in line 1 to define SIMULATION

juanka99 commented 1 year ago

MQTT is now connected. :-)

If you wanna see simulated data as long you have no serial connected remove the "//" in line 1 to define SIMULATION

Done!

Only this:

image

odig commented 1 year ago

You have to connect RX and TX via wire on the ESP32 for SIMULATION to work. Or wait for your level shifter. Simulation writes to pytes2 instead of pytes. And auto discover to pytes2_discover instead of homeassistant.

juanka99 commented 1 year ago

You have to connect RX and TX via wire on the ESP32 for SIMULATION to work. Or wait for your level shifter. Simulation writes to pytes2 instead of pytes. And auto discover to pytes2_discover instead of homeassistant.

RX and TX connected via wire, but no new entities in homeassistant:

image

odig commented 1 year ago

I need more info of your background. Are you new to HA and MQTT?

Homeassistant is mostly plug and play but you need to know some basics. The MQTT integration in Homeassistant (HA) looks in the "homeassistant" topic in MQTT for autodiscovery. The simulation intentionally writes to "pytes2_discover" instead of "homeassistant" otherwise tye entities will show up in your HA and need to get rid of them in your history afterwards. If you want to see them in your HA change the string "pytes2_discover" to "homeassistant".

The simulation was intented for me to see if the MQTT topics are filled in correct and the communication works.

MQTT is an universal tool. If you don't to use HA you can easily use any other home atomation system subscribing to the pytes(2) topics "pytes2/bat/1/volt" for example like NodeRed.

You have to get the whole picture. eboxToMqtt -> MQTT (topics: "homeassistant" for autodiscovery and "pytes" for values) -> homeassitant: MQTT integration

juanka99 commented 1 year ago

Hi again!

I have received the level shifter, I have connected it to the ESP32 and the Pytes, and the entities still do not appear in HA. I think there must be some other parameter in the configuration that needs to be changed and you don't remember it... Could this be?

image

odig commented 1 year ago

It is important to check the whole dataflow

1. Disable Simulation

Put the "//" back in before line 1 SIMULATION. build and reflash the ESP32.

Delete PYTES2 stuff in MQTT explorer

2. Is there a communication to the battery pack

check with telnet if you get an answer on "help" comand from PYTES. If not: RX and TX has to be swapped.

3. Are the needed MQTT topics available

You should have an pytes topic in MQTT with actual values "pytes/bat/1/1/volt". There should be an homeassistant topic in MQTT "homeassistant/sensor/pytes_bat_1_1/volt/config".

containing:

{ "name": "pytes_bat_1_1_volt", "unique_id": "pytes/bat/1/1/volt", "state_topic": "pytes/bat/1/1/volt", "device_class": "voltage", "state_class": "measurement", "qos": 0, "unit_of_measurement": "V", "value_template": "{{ value_json.value }}", "availability_mode": "all", "device": { "identifiers": [ "pytes/bat/1/1/volt" ], "name": "pytes bat1 1 (volt)", "sw_version": "" } }

3. Add and configure MQTT integration in HA:

You need to have the MQTT intergration added in HA:

image image

4. Entitys should showing up in HA

:-)

juanka99 commented 1 year ago
  1. SIMULATION was already disabled

  2. Could you tell me exactly what command I have to use to know if there is communication with the batteries?

  3. No homeassistant topic appears. Only the one in the following image:

image

  1. MQTT integration already had it up and running in HA, and entities don't show up in HA

I don't know what else :to try anymore. I am totally heartbroken :-((

odig commented 1 year ago

Before you can go further Step 2 has to function. Otherwise no data will be filled in MQTT and due to this there are no entitys in HA.

Things to test

image

This is the help direct from your battery's.

If this doesn't work the Serial connection is not established.

Possible causes:

odig commented 1 year ago

I checked your ESP32 photo. You used the wrong pins. You have to use the serial Interface on the ESP32. On your ESP32 Board it is on the pins marked RXD and TXD not G16 and G17.

https://medesign.seas.upenn.edu/uploads/Guides/NodeMCUPinout.png

If it doesn't work just switch the RX and TX Cable and give it a try.

Try put in "help" as command in telnet and press ENTER. If you get help youre nearly done. I'll bet the is the last problem. If "help" worked and no entities showing up please show the content of "homeassistant" in MQTT explorer.

juanka99 commented 1 year ago

A doubt:

I checked your ESP32 photo. You used the wrong pins. You have to use the serial Interface on the ESP32. On your ESP32 Board it is on the pins marked RXD and TXD not G16 and G17.

https://medesign.seas.upenn.edu/uploads/Guides/NodeMCUPinout.png

If it doesn't work just switch the RX and TX Cable and give it a try.

Try put in "help" as command in telnet and press ENTER. If you get help youre nearly done. I'll bet the is the last problem. If "help" worked and no entities showing up please show the content of "homeassistant" in MQTT explorer.

Any change here?

image

odig commented 1 year ago

Sorry i also have mixed up things. G16 and G17 on you board is correct! If "help" doesn't work just try connecting them the other way round.

Can you send detailed photos of ESP32, level shifter, western connector and your pytes front panel?

juanka99 commented 1 year ago

Sorry i also have mixed up things. G16 and G17 on you board is correct! If "help" doesn't work just try connecting them the other way round.

Can you send detailed photos of ESP32, level shifter, western connector and your pytes front panel?

All tests done. Everything remains the same. The "help" command still doesn't work. IMG_3298 IMG_3299 IMG_3300 IMG_3301 IMG_3302

odig commented 1 year ago

I rechecked the serial pins with your kind of ESP32 board these are correct (G16 and G17).

The last thing i see, is Green and Green/White are the other way round on my connection on the level shifter and Yellow and Green are the other way round.

so: 16/green on txd on ttl side of level shifter 17/yellow on rxd on ttl side of level shifter

green on txd on rs232 side of level shifter green/white on rxd on rs232 side of level shifter

image image image

juanka99 commented 1 year ago

Working!!!

image

Here was the problem:

image

Thank you for all!!!

odig commented 1 year ago

Yeah !!! Congrats to try so hard.

juanka99 commented 1 year ago

Job finished!

photo_2023-01-26_16-55-45

https://user-images.githubusercontent.com/32193776/214886923-ba49d65f-9316-4bef-a138-e3ff3c1f2a65.mp4

odig commented 1 year ago

MQTT config is fixed