hhaim / hass

home assistant and appdaemon scripts and configuration file
41 stars 16 forks source link

mqtt configuration for homeassistant in docker #7

Closed bereska closed 5 years ago

bereska commented 5 years ago

@hhaim @theunreal hi guys, thanks for the great project. I am new to homeassistant. Trying to follow your guide and set up a pulse sensor water meter. I have flashed a wemo D1 mini with Tasmota. Now I need to integrate it into my homeassistant 0.95.4. I have homeassistant, mosquitto, grafana, influxdb, etc. all running in docker containers under docker-compose. Mosquitto is accessed with login/password for each client. How do i configure the wemo and your custom-components/ to work with my setup? Thank you

bereska commented 5 years ago

i think I am slowly getting it but not quite. Since the platform is 'tasmota' for sensors in configuration.yaml, no need for mqtt configuration for each sensor, right?

hhaim commented 5 years ago

It is a good idea to have one docker for all the services. Tasmota talk to broker with Mqtt protocol. Component just need the topic. Hass is another client to the broker.

bereska commented 5 years ago

thanks for your advice the sensors show up in GUI as 'unavailable' if Tasmota is an mqtt client, it needs a login name and password i know how to create a new client user name and password in mosquitto but i don't know how to pass it to Tasmota

bereska commented 5 years ago

ha logs:

2019-07-25 23:54:33 WARNING (MainThread) [homeassistant.loader] You are using a custom integration for tasmota which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you do experience issues with Home Assistant., 2019-07-25 23:54:34 WARNING (MainThread) [homeassistant.components.mqtt] Signature of MQTT msg_callback 'custom_components.tasmota.sensor.state_received' is deprecated, 2019-07-25 23:54:34 WARNING (MainThread) [homeassistant.components.mqtt] Signature of MQTT msg_callback 'custom_components.tasmota.sensor.tele_received' is deprecated

hhaim commented 5 years ago

You need to configure hass Mqtt see here: https://github.com/hhaim/hass/blob/dee4749f4991a86776301faf26a681b0de522416/configuration.yaml#L31

bereska commented 5 years ago

thank you I already have it configured for mosquitto like this in configuration.yaml:

mqtt: discovery: true discovery_prefix: 'homeassistant' broker: localhost port: 1883 client_id: home-assistant-1 username: ha password: 'superstrongpassword' birth_message: topic: "homeassistant/status" payload: 'online' qos: 1 retain: True will_message: topic: "homeassistant/status" payload: 'offline' qos: 1 retain: True

my homeassistant in docker (ha) and all the other mqtt clients successfully connected to mosquitto am i missing something here? thank you for your help

hhaim commented 5 years ago

Looks ok. You don’t need to do anything else. Verify that it is connected to the broker.

bereska commented 5 years ago

I think so, too the homeassistant (ha) is connected per mosquitto logs: '1564088068: New client connected from 172.18.0.1 as home-assistant-1 (c1, k60, u'ha')

172.18.0.1 is homeassistant docker network address 172.18.0.6 is mosquitto docker network address

i can access the wemo in browser at http://192.168.2.154/ the homeassistant runs on rpi3 at http://192.168.2.230/

the meter is not connected to the water line, but the wemo takes readings from it if I just blow some air through:

Counter1 23

yet, the sensors show up in GUI as 'unavailable' any ideas? thank you

hhaim commented 5 years ago

I would log into hass docker and run mosquitto_sub -t topic (and server/user/password)

To verify that topic are redirect.

I don’t think you have a component issue.

bereska commented 5 years ago

pi@bereskapi-ha:~ $ mosquitto_sub -v -t homeassistant/status -u ha -P ######## homeassistant/status online ^C pi@bereskapi-ha:~ $ mosquitto_sub -v -t tele/hass1/LWT -u ha -P ######### ^C pi@bereskapi-ha:~ $

bereska commented 5 years ago

also I could not find where I need to put these values: Tasmota configuration (once) CounterDebounce 1000 TelePeriod 60 SetOption36 20

bereska commented 5 years ago

I figured I need to run the above commands in Console, but I can't pair your custom component with homeassistant, the sensors are still show up as 'unavailable' pls help

bereska commented 5 years ago

ant these warnings are ha logs:

2019-07-25 23:54:33 WARNING (MainThread) [homeassistant.loader] You are using a custom integration for tasmota which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you do experience issues with Home Assistant., 2019-07-25 23:54:34 WARNING (MainThread) [homeassistant.components.mqtt] Signature of MQTT msg_callback 'custom_components.tasmota.sensor.state_received' is deprecated, 2019-07-25 23:54:34 WARNING (MainThread) [homeassistant.components.mqtt] Signature of MQTT msg_callback 'custom_components.tasmota.sensor.tele_received' is deprecated

hhaim commented 5 years ago

Hi, The warning are expected, this is not the issue. I think you have a networking issue betwean the dockers.

I suggest to do this to verify were it:

1) Let's say your topic is water_out

In the GUI in the water sensor Console you will see something like this:

19:07:36 MQT: tele/water_out/STATE = {"Time":"2019-07-27T19:07:36","Uptime":"1T12:15:39","Vcc":2.710,"SleepMode":"Dynamic","Sleep":50,"LoadAvg":19,"POWER":"OFF","Wifi":{"AP":1,"SSId":"","BSSId":"","Channel":4,"RSSI":46,"LinkCount":2,"Downtime":"0T00:00:16"}}
19:07:36 MQT: tele/water_out/SENSOR = {"Time":"2019-07-27T19:07:36","COUNTER":{"C1":155834}}

Now login into the hass docker and run this and wait 60 sec

mosquitto_sub -u [user] -P [pass] -t +/water_out/#

Replace user/password with the right values. You should see the same like in the Console

{"Time":"2019-07-27T19:06:36","Uptime":"1T12:14:39","Vcc":2.710,"SleepMode":"Dynamic","Sleep":50,"LoadAvg":19,"POWER":"OFF","Wifi":{"AP":1,"SSId":"","BSSId":"","Channel":4,"RSSI":48,"LinkCount":2,"Downtime":"0T00:00:16"}}
{"Time":"2019-07-27T19:06:36","COUNTER":{"C1":155834}}

If you don't see it, try the same from the broker docker

If you don't see the messages you will need to debug docker configuration.

In my case hass and broker and iot are on the same network in case of mqtt with docker there is a NAT involved so you need to know what you are doing

hhaim commented 5 years ago

Can we close this?

bereska commented 5 years ago

hi @hhaim, not quite. I have tried your solution, it didn't work for me, sensors still 'unavailable' in GUI. Then I just configured Wemos for mqtt. I showed up in GUI. It works great except for the known problem of resetting counter after power loss/reboot. I know your library deals with it somehow. Is there there a way to implement your solution just for this one water meter pulse sensor? Maybe like running Rules in console? Thank you

bereska commented 5 years ago

or python script maybe?

hhaim commented 5 years ago

Let me see if I understand, A simple mqtt sensor works (except the reset issue) and my custom component does not (unavailablel)?

bereska commented 5 years ago

yes, correct. And like you said, it's probably because of my docker network setup which I don't want to change since I have 9 docker containers and 30+ sensors running just fine. It is just this bloody water meter pulse sensor that I'm struggling with)

bereska commented 5 years ago

00:00:00 CFG: Loaded from flash at F6, Count 182 00:00:00 Project sonoff Sonoff Version 6.6.0(release-sonoff)-2_3_0 00:00:00 WIF: Connecting to AP2 TP-LINK_72DC in mode 11N as esp8266_water-1825... 00:00:04 WIF: Connected 00:00:04 HTP: Web server active on esp8266_water-1825 with IP address 192.168.2.71 00:00:05 MQT: Attempting connection... 00:00:05 MQT: Connected 00:00:05 MQT: tele/esp8266_water/LWT = Online (retained) 00:00:05 MQT: cmnd/esp8266_water/POWER = 00:00:05 MQT: tele/esp8266_water/INFO1 = {"Module":"Sonoff Basic","Version":"6.6.0(release-sonoff)","FallbackTopic":"cmnd/DVES_42C721_fb/","GroupTopic":"sonoffs"} 00:00:06 MQT: tele/esp8266_water/INFO2 = {"WebServerMode":"Admin","Hostname":"esp8266_water-1825","IPAddress":"192.168.2.71"} 00:00:06 MQT: tele/esp8266_water/INFO3 = {"RestartReason":"Power on"} 00:00:06 MQT: stat/esp8266_water/RESULT = {"POWER":"ON"} 00:00:06 MQT: stat/esp8266_water/POWER = ON 13:58:03 MQT: tele/esp8266_water/STATE = {"Time":"2019-07-31T13:58:03","Uptime":"0T00:00:14","Heap":16,"SleepMode":"Dynamic","Sleep":50,"LoadAvg":19,"POWER":"ON","Wifi":{"AP":2,"SSId":"TP-LINK_72DC","BSSId":"B0:4E:26:D5:72:DC","Channel":13,"RSSI":84,"LinkCount":1,"Downtime":"0T00:00:04"}} 13:58:03 MQT: tele/esp8266_water/SENSOR = {"Time":"2019-07-31T13:58:03","COUNTER":{"C1":4}}

hhaim commented 5 years ago

@bereska I've just tested it with latest hass and this

sensor:

  - platform: uptime

  - platform: tasmota
    name: water_total
    stopic: water_out
    id: 1
    unit_of_measurement: 'l'
    icon: mdi:water-pump
    expire_after: 300
    value_template: "{{ (45497 + (value))|int }}"

and it works fine

image

image

so it is something else

please send

  1. mqtt configuration that works
  2. custom comp that does not work
bereska commented 5 years ago

Снимок экрана 2019-07-31 в 23 30 51

as for the custom comp it is your custom_components folder placed into my config directory

bereska commented 5 years ago

I just tried one more time from scratch per your guide It looks like the sensor cannot connect to your custom component

00:00:00 CFG: Loaded from flash at F9, Count 11 00:00:00 Project sonoff Sonoff Version 6.6.0(release-sonoff)-2_3_0 00:00:00 WIF: Connecting to AP1 bereska24 in mode 11N as sonoff-1825... 00:00:04 WIF: Connected 00:00:04 HTP: Web server active on sonoff-1825 with IP address 192.168.2.71 22:10:46 RSL: tele/sonoff/STATE = {"Time":"2019-07-31T22:10:46","Uptime":"0T00:00:59","Heap":14,"SleepMode":"Dynamic","Sleep":50,"LoadAvg":19,"POWER":"ON","Wifi":{"AP":1,"SSId":"bereska24","BSSId":"2C:FD:A1:3E:16:50","Channel":4,"RSSI":20,"LinkCount":1,"Downtime":"0T00:00:04"}} 22:10:46 RSL: tele/sonoff/SENSOR = {"Time":"2019-07-31T22:10:46","COUNTER":{"C1":20}}

bereska commented 5 years ago

even if I change topic to water_out in mqtt config of the sensor, it is still 'unavailable' in GUI

2:35:59 RSL: tele/water_out/STATE = {"Time":"2019-07-31T22:35:59","Uptime":"0T00:11:59","Heap":13,"SleepMode":"Dynamic","Sleep":50,"LoadAvg":19,"POWER":"ON","Wifi":{"AP":1,"SSId":"bereska24","BSSId":"2C:FD:A1:3E:16:50","Channel":4,"RSSI":26,"LinkCount":1,"Downtime":"0T00:00:04"}} 22:35:59 RSL: tele/water_out/SENSOR = {"Time":"2019-07-31T22:35:59","COUNTER":{"C1":20}}

hhaim commented 5 years ago

You are sending the web console output. This does not prove the Mqtt is working. Please run the mosqutto_sub procedure above or/and send the hass Mqtt sensor yaml that you claim that works.

You are sending irrelevant information and not answering the questions. It becoming difficult to help you

hhaim commented 5 years ago

Tasmota User/password for the Mqtt does not seem right!

bereska commented 5 years ago

this sensor works:

bereska commented 5 years ago

"Tasmota User/password for the Mqtt does not seem right!" - I don't get it. Do i need to create an mqtt user/password for tasmota?

bereska commented 5 years ago

all my sensors are inside ha configuration.yaml, not a separate sensors.yaml. Does it matter for your custom_component?

hhaim commented 5 years ago

" Please send YAML

  1. mqtt configuration that works
  2. custom comp that does not work "
bereska commented 5 years ago

sorry, I don't get it, I already sent it ti you before, here it is again:

mqtt: discovery: true discovery_prefix: 'homeassistant' broker: localhost port: 1883 client_id: home-assistant-1 username: ha password: superstrongpassword birth_message: topic: "homeassistant/status" payload: 'online' qos: 1 retain: True will_message: topic: "homeassistant/status" payload: 'offline' qos: 1 retain: True

hhaim commented 5 years ago

This is the mqtt client configuration, I need to see the sensor that is unavailable (uses the custom component)

It should be something like this:

sensor:

  - platform: tasmota
    name: water_total
    stopic: water_out
    id: 1
    unit_of_measurement: 'l'
    icon: mdi:water-pump
    expire_after: 300
    value_template: "{{ (45497 + (value))|int }}"
bereska commented 5 years ago

that is exactly it! I followed your guide!

hhaim commented 5 years ago

@bereska very hard to get a clear answer to a very simple question.

I assume your answer is this:

  1. This sensor works
sensor:

   platform: mqtt
   name: "Water Meter Home"
   state_topic: "tele/esp8266_water/SENSOR"
   value_template: "{{ value_json['COUNTER'].C1|int *5 }}"
   unit_of_measurement: "Liters"
   qos: 1
  1. This custom sensor does not work
sensor 
   platform: tasmota
   name: water_total
   stopic: water_out
   id: 1
   unit_of_measurement: 'l'
   icon: mdi:water-pump
   expire_after: 300
   value_template: "{{ (45497 + (value))|int }}"

Am I correct?

bereska commented 5 years ago

yes

hhaim commented 5 years ago

How could it work? it should be

sensor 
   platform: tasmota
   name: water_total
   stopic: esp8266_water
   id: 1
   unit_of_measurement: 'l'
   icon: mdi:water-pump
   expire_after: 300
   value_template: "{{ (45497 + (value))|int }}"
bereska commented 5 years ago

thank you, let me correct this and report back also I assume that 'value_template: "{{ (45497 + (value))|int }}"' is specific to your water meter with initial reading of 45497, right? so I can adjust it according to mine? I figured my sensor gives a pulse every 5 liters even though the meter passport says 1 pulse per 10 liters (go figure!) so in my case that line would be 'value_template: "{{ (630 + (value))|int *5}}", correct? thanks for bearing with stupid me

bereska commented 5 years ago

ok, the sensor finally shows up in GUI but it does not get updated even thought the sensor keeps on sending new values as the water flows( here is my config from yaml:

thanks for your patience

hhaim commented 5 years ago

Have a look here: https://www.home-assistant.io/docs/configuration/templating/

bereska commented 5 years ago

I tried the following but it gives me an error homeassistant.exceptions.TemplateError: UndefinedError: 'value_json' is undefined

bereska commented 5 years ago

sorry, this is full

bereska commented 5 years ago

this same very 'value_template: "{{ value_json['COUNTER'].C1 | int *5 }}"' works just fine with an mqtt sensor

bereska commented 5 years ago

I don't think the template is wrong, the sensor just fails to get the values to homeassistant

2019-08-02 00:54:56 DEBUG (MainThread) [homeassistant.components.mqtt] Subscribing to tele/esp8266_water/LWT, 2019-08-02 00:54:56 DEBUG (MainThread) [homeassistant.components.mqtt] Subscribing to tele/esp8266_water/STATE, 2019-08-02 00:54:56 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on tele/esp8266_water/LWT (retained): b'Online', 2019-08-02 00:54:56 DEBUG (MainThread) [homeassistant.components.mqtt] Subscribing to tele/esp8266_water/SENSOR

pi@bereskapi-ha:~ $ mosquitto_sub -v -t +/esp8266_water/# -u ha -P password tele/esp8266_water/LWT Online

hhaim commented 5 years ago

@bereska better to close this and move the thread to hass forum. Your questions are not related to the component

bereska commented 5 years ago

How come 'not related'? I have two identical pulse sensors: one configured with mqtt, the other with your component. The first one works (except for power/reboot issue), the second doesn't

hhaim commented 5 years ago

There are 27 messages in this thread and still there is no Mqtt information, no definition of “does not work”. The only issue I saw relates to not reading the instructions and the other relates to templates that is general engine that you can google /ask in other places. If you have specific component question please provide the full information in one message. Mqtt/template/networking questions are not for here.

hhaim commented 5 years ago

Too old