MQTT Icon Configuration Help

Has anyone been able to successfully setup an MQTT motion sensor icon?

I am using lovelace. I have tried icon_template (which is not available for sensor.mqtt) as well as device_class. Device_class worked, but there is not a motion sensor device class for MQTT sensors…as far as I can tell. I am able to get it working for other sensors, but sensor.mqtt does not support icon_template.

I would like to have an icon that changes from mdi:eye (when no motion) to mdi:walk when motion is detected.

For an on/off only motion sensor wouldn’t it be better to create a binary_sensor instead of a sensor?

Then you should be able to use the motion device class for it.

I thought about that, but was curious if there was another option.

Here is my test sensor:

  - platform: mqtt
    state_topic: "my/sensor"
    payload_on: "motion"
    payload_off: "no motion"
    value_template: "{{ value_json.motion_status }}"
    device_class: motion

This shows the mdi:walk icon and highlights mdi:walk with yellow when motion found.

Am I able to set the icon to mdi:eye when no motion, and mdi:walk when motion detected? Also, the value returns “clear” and “detected”. How do I change the value to be “motion” and “no motion”.

then the next step is to create a mqtt template sensor. I think you can set all that in the templates.

For future reference, I ended up using a template sensor. Here is my example. There is some clean up to do…but you get the point. Thanks all.

  - platform: mqtt
    state_topic: "my/sensor"
    name: "PIR MQTT"
    value_template: '{{ value_json.motion }}'
  - platform: template
    sensors:
      pir:
        friendly_name: "PIR"
        entity_id: sensor.pir_mqtt
        value_template: "{%if states.sensor.pir_mqtt.state == 'motion detected' %} motion {% else %} {{ states.sensor.pir_mqtt.state }} {% endif %}"
        icon_template: "{%if states.sensor.pir_mqtt.state == 'standby' %} mdi:eye {% else %} mdi:walk {% endif %}"