Set value of input_text by json attribute received from mqtt sensor

What I intend is to fill text_input boxes by an attribute of a json mqtt message.
In config.yaml I set up the mqtt sensor which is basically working as the payload of my message isd shown. Also the text_input seems to be OK as on a state change of my mqtt sensor a fixed value can be set. But all my attempts to get the value of a json key failed.

the received payload is:
{“type”: 55 , “loc”: “Diele”, “sa”: 44 , “family”: “0x60” , “rom”: “0x0011223344556677” }

config.yaml is this:

mqtt:

  sensor:
    - name: "owinet_eeprom"
      state_topic: "owinet/eeprom/sensor/address"
      json_attributes_topic: "owinet/eeprom/sensor/address"
      json_attributes_template: "{{ value_json.value }}" 


input_text:
  text1:
    name: owinet_json_rom
    initial: "nothing"
      

in automations.yaml:

- alias: eeprom_json_rom
  trigger:
    platform: state
    entity_id: sensor.owinet_eeprom
  action:
    - service: input_text.set_value
      target:
        entity_id: input_text.text1
      data:
#        value: "TEST"  # OK Works
         value_template: "{{ state_attr('sensor.owinet_eeprom','rom')}" # Nothing happens
#        value: "{{ value_json.rom)}"     # Nothing happens

Hence, I’n not sure if the value_template is wrong or the mqtt sensor json settings of the sensor are not OK.

Finally Iwant to achieve an input_text for each of the attributes in my json. Next I want to edit the values and publisch an mqtt message with the modified values back.

Hope someon can help on this.

Why do you need an MQTT Sensor for this application?

I suggest using an automation with an MQTT Trigger. When it receives a payload, it iterates through all of the payload’s keys, and stores each key’s value in a corresponding input_text.

A separate automation uses a State Trigger to monitor all of the inout_texts. If the value of any one of the input_texts changes, it publishes the value of all input_texts, as a single payload.

Hello Taras,
thank you very much for that hint. Home Assistant is so powerfull that I will probably need years to make use of all the concepts it provides. :slightly_smiling_face:
I had a look into the documentation and got thanks to your reply an imagination how the value_template: “{{ value_json.state }}” works.
My understanding is by now that I need a trigger for each of the keys I would like to see in the according text box. Is this right?

However, thanks a lot for your reply. It turns out to be the solution

1 Like