MQTT export component

The MQTT export component is a custom component which is sending all states and some details in one MQTT message.

Put the file mqtt_export.py file in the folder custom_components of your local Home Assistant configuration folder .homeassistant.

Your configuration.yaml file needs an entry for the component including the publishing topic (publish_topic).

mqtt_export:
  publish_topic: "home/states"

Sample output:

    {
       "details":{
          "latitude":46.9432,
          "temperature_unit":"\u00b0C",
          "version":"0.17.0.dev0",
          "location_name":"Test room",
          "time_zone":"Europe/Zurich",
          "longitude":7.6034,
          "components":[
             "recorder",
             "http",
             [...]
             "automation"
          ]
       },
       "states":[
          {
             "attributes":{
                "friendly_name":"Bathroom window",
                "sensor_class":"connectivity"
             },
             "last_updated":"14:10:57 06-04-2016",
             "state":"off",
             "entity_id":"binary_sensor.bathroom_window",
             "last_changed":"14:10:57 06-04-2016"
          },
          {
             "attributes":{
                "next_setting":"18:06:45 06-04-2016",
                "next_rising":"04:56:02 07-04-2016",
                "friendly_name":"Sun",
                "elevation":37.39
             },
             "last_updated":"14:11:30 06-04-2016",
             "state":"above_horizon",
             "entity_id":"sun.sun",
             "last_changed":"14:11:09 06-04-2016"
          },
          [...]
       ]
    }

Source: https://github.com/fabaff/home-assistant-mqtt-export

6 Likes

Why is this not a official component?
Have been working on my own export component, then I suddenly found this. Think I had found it earlier if it was official.

thanks.
How to get data and create new topic?

Subscribe to the topic you stated in the configuration.

I did, but how to extract data for each state and have a topic for each state

{“states”: [{“state”: “off”, “attributes”: {“battery_level”: 53, “friendly_name”: “Motion sensor kitchen”, “No motion since”: “1200”, “device_class”: “motion”}, “last_changed”: “2017-05-13T21:18:27.634595+00:00”, “entity_id”: “binary_sensor.motion_sensor_158d000127acc3”, “last_updated”: “2017-05-13T21:37:17.988026+00:00”}, {“state”: “scening”, “attributes”: {“entity_id”: [“group.livingroom_lights”], “friendly_name”: "White

Templating…

Yep, understand, although too complicated for me.

I wonder if anyone can help do an example (using the above usage case).

Most important feature, for me now, is to know if the entity_id (light and switch) is ON or OFF

Perhaps you tell us what you want to archive exactly? A list of entities and their states? If so, then it’s still about parsing the MQTT payload.

all topic like
light/livingroom_light_central
group/livingroom_lights
script/turn_on_power_plug

and so on.

For the state, I understand I will need to subscribe to the topic created, but I do not have to create all topics in HASS (mqtt.publish for each entity_id)

I hope I am clear (and I hope it make sense what I want :smile:)

Is there a way to force trigger to send all again?

If I restart my main hass I could publish something that resend all from secondary hass with mqtt_export