How to change attributes of a discover mqtt entity? forever to static

so it has nothing to do with this topic, got it.
thanks :slight_smile:

You can modify the discovery payload created by a physical device or even create your own entity via MQTT Discovery.

For example, run this script from the Services page and it will create a new entity called light.example.

  example_create:
    alias: 'Create Example MQTT Light'
    sequence:
      service: mqtt.publish
      data:
        topic: 'homeassistant/light/example/config'
        retain: true
        payload: >
          {
            "name": "Example",
            "unique_id": "ABC123",
            "stat_t": "home/example",
            "cmd_t": "home/example/set",
            "bri_stat_t": "home/example/brightness",
            "bri_cmd_t": "home/example/brightness/set"
          }

The newly created entity will appear in States, Entities, and MQTT Integrations views.

Let’s say you just ran the script and Home Assistant has created light.example. Now you want to add an option like the color temperature state topic. Simply add it to the script’s payload, (reload scripts), run it again and Home Assistant will not create a new entity but simply update the existing one. For example, I’ve added two topics for handling color temperature:

  example_create:
    alias: 'Create Example MQTT Light'
    sequence:
      service: mqtt.publish
      data:
        topic: 'homeassistant/light/example/config'
        retain: true
        payload: >
          {
            "name": "Example",
            "unique_id": "ABC123",
            "stat_t": "home/example",
            "cmd_t": "home/example/set",
            "bri_stat_t": "home/example/brightness",
            "bri_cmd_t": "home/example/brightness/set",
            "clr_temp_stat_t": "home/example/color",
            "clr_temp_cmd_t": "home/example/color/set"
          }

Running this revised script won’t create a light.example_02 but simply update the existing one.

If you want to delete light.example, run this script. It simply publishes an empty retained message to the entity’s discovery topic.

  example_delete:
    alias: 'Delete Example MQTT Light'
    sequence:
      service: mqtt.publish
      data:
        topic: 'ha/light/example/config'
        retain: true
        payload: ''

NOTE: Deleting the entity this way will make Home Assistant remove the entity from States and Entities views. However, in the MQTT Integrations view it will mark the entity as Unavailable. In other words, the entity continues to exist in the entity registry. You can click the entity to reveal a dialog-box that allows you to Remove Entity (from the registry). Unfortunately, there’s a bug and it won’t reveal that dialog-box until you restart Home Assistant. I’ve posted it as bug in the home-assistant-polymer repo (it may actually be due to a bug in the backend, not the frontend, but I’ll let the developers decide that).

trial by fire. I’ve had to do it for some zwave lights to get functionality.

1 Like