rorr73 / LifeSOSpy_MQTT

MQTT Client to communicate with LifeSOS alarm systems.
MIT License
5 stars 2 forks source link

lifeSOSpy_MQTT with home assistant in docker container #2

Closed bereska closed 5 years ago

bereska commented 5 years ago

hi Robert, I hate to bother you again I struggle to have lifesospy_mqtt started after homeassistant restart and I need your help

as you know I have already enabled lifesospy_mqtt as a systemd service and works just fine after pi reboot, everything starts right up however if I just restart homeassistant ('docker restart homeassistant'), lifesosd.service keeps on running but it never hooks up with homeassistant and I have to manually restart lifesosd.service ('sudo systemctl restart lifesosd.service')

I think the problem is that I run homeassistant in docker container and lifesospy_mqtt was installed on host I have googled this problem around but could not find a solution Please let me know your thoughts regards, Dmitry

rorr73 commented 5 years ago

Hi Dmitry,

LifeSOSpy_MQTT should configure itself automatically in Home Assistant as soon as it comes online, provided the following are in place:

  1. Home Assistant is configured to enable automatic discovery, and announce when it is online. This is done via it's configuration.yaml file. Here is the relevant section from mine as an example:

    mqtt:
    # My Mosquitto broker instance
    broker: 127.0.0.1
    
    # Listen for MQTT clients and automatically configure devices
    discovery: true
    discovery_prefix: 'homeassistant'
    
    # Notify any MQTT clients when we come online and go offline
    birth_message:
    topic: "homeassistant/status"
    payload: 'online'
    qos: 1
    retain: True
    will_message:
    topic: "homeassistant/status"
    payload: 'offline'
    qos: 1
    retain: True
  2. LifeSOSpy is configured with the correct discovery prefix and birth topic/payload that matches what you have defined in Home Assistant (above). Here is an example from my config.yaml:

    # Settings for the translator between LifeSOS and MQTT
    translator:
    
    # To automatically configure devices in Home Assistant, ensure this line
    # matches the setting in Home Assistant's config file. Note any devices and
    # switches will need to be assigned a 'ha_name"' to be exported.
    # Refer https://www.home-assistant.io/docs/mqtt/discovery/
    ha_discovery_prefix: homeassistant
    
    # Topic and Payload to announce Home Assistant has come online. When received,
    # our MQTT client will send out the device configurations for discovery.
    ha_birth_topic: homeassistant/status
    ha_birth_payload: online

If you change either, you will need to restart HA and/or LifeSOSpy respectively.

How this works is LifeSOSpy subscribes to the birth topic, and when it sees HA announce it is online (which happens every time it starts up), it sends the full configuration of all LifeSOS devices using the homeassistant discovery prefix, so they should appear almost immediately on startup.

If you already have this configuration and it is still not working, the only other thing I can think of is your MQTT broker; are you using a separate instance (eg. Mosquitto) or the built-in one in Home Assistant? If it is the built-in one, I would suggest trying a Mosquitto Docker instance, as this will ensure the MQTT broker remains running whenever you need to restart HA (ie. it won't sever the connection with LifeSOSpy or any other MQTT clients).

bereska commented 5 years ago

hi Robert, everything was set up just like you said: both config files in homeassistant and lifesospy_mqtt had all the necessary topics and prefix, and I'm running mosquitto in docker container, too but after reading your comments I just had a closer look and my homeassistant config and sure enough I had discovery_prefix: 'homeassistant' without ''( now all starts right up after 'docker restart homeassistant' like it should I'm so sorry for waisting your time on such small issues thank you very much for your help

also I'm now struggling with zigbee lights which suddenly stop responding from time to time and I'm worried that my home-assistant_v2.db has grown to 1.5 Gb by now and keeps on growing at about 1 Mb/hour rate is it something that you had issues with in your homeassistant experience?

thank you Dmitry

rorr73 commented 5 years ago

You're welcome, just glad it's all working and you're finding it useful.

Re ZigBee; I do use some ZigBee lights (Philips Hue) and switches (Xiaomi) without issue. In my case, I'm using Deconz (with a Conbee USB) as the hub. All I can suggest is starting with whatever you're using as your hub, and determining if it has any logging functionality that may help in determining where the fault is, as well as looking at forums like the Home Assistant community forum - chances are someone with the same hub may have encountered similar issues.

Re Home Assistant's database size growing and growing; yes, I get that too. It logs everything without deleting, unless you specifically configure a purge interval. Personally I just delete it from time to time when it gets too big, but a better way to manage it would be to use the purge_keep_days setting mentioned in the HA docs here.

bereska commented 5 years ago

that's right, these guys got close but never really solved this issue https://github.com/zigpy/bellows/issues/124 i use Sengled bulbs with HUSBZB-1 usb as a zha hub

re db: are you using built-in mysqlite db or something else? what is your recorder/purge configuration? thank you

rorr73 commented 5 years ago

Just the built-in sqlite database; haven't bothered to adjust the configuration at all. Perhaps one day if deleting the database periodically starts to become annoying I might look into configuring the purge settings or move it to one of the MySQL instances running on my NAS.

bereska commented 5 years ago

thank you, Robert