How to confgure MQTT sensors published by another homeassistant

I could like to “copy” some sensors from one homeassistant to another, so I configure “MQTT Statestream” on HASS A:

And try to configure a MQTT sensor on HASS B:

It looks like the sensor’s state is copied normally, but not its attributes, because “MQTT Statestream” separates sensor’s attributes to different topics.
For a real example, a sensor “pzemac_energy_peak” with an attribute “last_period”, I try to listen “homeassistant/sensor/pzemac_energy_peak/#” and can see:

Message 100 received on homeassistant/sensor/pzemac_energy_peak/state at 1:17 PM:
QoS: 0 - Retain: false

Message 101 received on homeassistant/sensor/pzemac_energy_peak/last_period at 1:17 PM:
QoS: 0 - Retain: false

So I configure a MQTT sensor “pzemac_test” on HASS B:

  - platform: mqtt
    name: pzemac_test
    state_topic: "homeassistant/sensor/pzemac_energy_peak/state"
    json_attributes_topic: "homeassistant/sensor/pzemac_energy_peak/last_period"

Then on HASS B I can see sensor.pzemac_test only have state “1.4”, but no matter how I modified the configuration, the attribute “last_period” won’t show out.

This problem really confusing me… I tried to search for times but can’t find any similar discussion over the internet… Does anyone has any idea? It will be much appreciated…

I’ve been through this, and it’s possible, but an absolute pain in the proverbial.

Much easier is to install this custom component and configure it appropriately on the main system, the one you want to get the values into.

1 Like

Hi Tinkerer,

Really thanks for your suggestion :slight_smile:

I’ve looked into the customer component, it looks complicated to add it, but I only would like to link a few entities. (And the reason why I separate my HASS is in order to make it lighter…)

I think I should try to just add the attribute as a different entity, but if in future “MQTT Statestream” would publishes entities like zigbee2mqtt (All in one topic), I think things will be much eaiser.

That’s because the sensor’s configuration is missing:


which creates the attribute using the value from:


Try this:

  - platform: mqtt
    name: pzemac_test
    state_topic: "homeassistant/sensor/pzemac_energy_peak/state"
    json_attributes_topic: "homeassistant/sensor/pzemac_energy_peak/last_period"
    json_attributes_template: >
      {"last_period": "{{value}}"}

I confirmed it works using this:

  - platform: mqtt
    name: example
    state_topic: "example/state"
    json_attributes_topic: "example/last_period"
    json_attributes_template: >

I published yes to example/state and 2020-03-07 to example/last_period. Here’s the result:

Screenshot from 2020-03-07 08-50-41

Not at all, and even less so if you use HACS

Trivial to do, I only link a specific set of entities.

Hi 123,

Nice shoot! I changed “value” to “value_json” (since the last_period is a number) and now the attribute is successfully added :wink:
Thanks for taking your time to help on my question!

Hi Tinkerer,

Again, highly appreciate your suggestion, I think I could use this on a different scenario :wink:

If last_period is a number, just remove the double-quotes surrounding {{value} like this:

    json_attributes_template: >
      {"last_period": {{value}}}

Using the variable value_json instructs Home Assistant to expect the received data to be in JSON format. If it’s not in JSON format, then you use value.

Yes! it also work smoothly, just like a charm :laughing: :laughing: :laughing: