[retain] is an invalid option for [sensor.mqtt]

Hi everyone!

I upgraded to 0.87 today and i now have a new error regarding retain flags.
The error i get is the following:
2019-02-07 08:10:36 ERROR (MainThread) [homeassistant.config] Invalid config for [sensor.mqtt]: [retain] is an invalid option for [sensor.mqtt].

The sensor worked in version 0.86.4 and before but not after the upgrade.
The sensor (actually sensors, i’ve got 16 mqtt sensors and none of them are working since the upgrade) are configured like this:

  • platform: mqtt
    name: “Temperatur”
    unit_of_measurement: ‘°C’
    state_topic: “home-assistant/temp”
    retain: true

######## EDIT #########

I downgraded to 0.86.4 and the sensors are working again.
Its either an issue with 0.87 or something needs to be configured in another way with that specific release.

Any ideas?

There’s a Breaking Change for the MQTT platform.
Seems like the retain option is not available anymore.

Well that is AWESOME news! The trouble that causes…

A mqtt sensor needs no retain option IMO.
The device that publishes to mqtt should set it, if needed.

1 Like

100% agree… setting it in HA caused a world of problems on restarts so great it’s gone from HA.

I 100% disagree. If used correctly retain is a valuable tool. Is it only the mqtt sensor that is affected? Or will I have to rethink the way I store global variables like this:

  action:
    service: mqtt.publish
    data_template:
      payload_template: >
        {% if is_state('binary_sensor.recycling_week', 'on') %}
          OFF
        {% else %}
          ON
        {% endif %}
      topic: 'home-assistant/variable/recycling_week'
      retain: true

I 100% disagree too regarding that its good that its disabled.
There is a reason that the retain flag is a part of MQTT and i need it for the sensors i’ve got.

This must be an error of some sort.

####### EDIT #######
Retain is still valid for switches, that however doesn’t help me at all:

The retain flag may be set for messages being sent from HA.

Setting the parameter in your yaml never did anything for MQTT messages being received by HA, such as in sensors.

2 Likes

This.

I don’t think people understood the difference, and just stuck the flag there thinking it was going to do something for their sensors. For sensors, HA is SUBSCRIBED to a topic, and retain requires the PUBLISHER to push that flag.

2 Likes

Ah gotcha. That makes sense.

So Im having an issue as well since updating to 87.0
Invalid config for [binary_sensor.mqtt]: [command_topic] is an invalid option for [binary_sensor.mqtt]. Check: binary_sensor.mqtt->command_topic. (See /config/configuration.yaml, line 149). Please check the docs at https://home-assistant.io/components/binary_sensor.mqtt/
- platform: mqtt
device_class: motion
state_topic: “smartthings/Kitchen Motion Sensor/motion/state”
command_topic: “smartthings/Kitchen Motion Sensor/motion/cmd”
name: ‘Kitchen Motion Sensor’
payload_on: “active”
payload_off: “inactive”
retain: true
scan_interval: 5

This no longer works and shows as entity not available in the frontend. Any ideas? I have been unable to fix it

command_topic is not a valid option for a binary_sensor. Home Assistant 0.87 no longer just ignores invalid options (like it did in previous releases) it now identifies and complains about them.

Remove it from the binary_sensor’s configuration. It makes no sense that it’s there. You only receive the state of a binary_sensor (your’s is configured as a motion sensor), you don’t send commands to a motion sensor.

PS

You might as well remove retain: true from that binary_sensor’s configuration as well because that’s also an invalid option.

where should I move it to? and I already removed the retain since I reading up above

It shouldn’t be there at all. You don’t send COMMANDS to binary_sensors. They only show state of that sensor. You can’t send a command to it.

i misunderstood that you meant the command-topic, I thought you meant the sensor itself.

  • platform: mqtt
    device_class: motion
    state_topic: “smartthings/Kitchen Motion Sensor/motion/state”
    name: ‘Kitchen Motion Sensor’
    payload_on: “active”
    payload_off: “inactive”
    scan_interval: 5

I updated it to this and now it doesn’t work at all, although it shows the entity OK now
sensor:

  • platform: mqtt
    name: ‘Kitchen light Sensor’
    state_topic: “smartthings/Kitchen Motion Sensor/illuminance/state”

This also stopped working it shows a state of Unknown now

I searched the documentation for both MQTT Sensor and MQTT Binary Sensor and scan_interval is not listed as a valid option. Remove it, for good measure.

If this does not work:

- platform: mqtt
  device_class: motion
  state_topic: "smartthings/Kitchen Motion Sensor/motion/state"
  name: "Kitchen Motion Sensor"
  payload_on: "active"
  payload_off: "inactive"

then I would use an MQTT client to confirm the state_topic is actually receiving messages containing active or inactive. If the topic is receiving the expected messages, I would then confirm Home Assistant is properly logged in to the MQTT Broker (check the Broker’s logs). If it is then … I would run out of ideas and conclude something is borked in 0.87. :slight_smile:

The Kitchen Light Sensor should work. I believe any MQTT sensor will report Unknown if the MQTT Broker has not yet received a message for the given topic. However, it you are seeing Unknown even when the sensor device is obviously detecting a change in illuminance, then I would double-check Home Assistant’s connection to the MQTT Broker (or even, in this case, SmartThings connection to the Broker given that you are probably using the so-called Smarter Things Bridge).

- platform: mqtt
  name: "Kitchen light Sensor"
  state_topic: "smartthings/Kitchen Motion Sensor/illuminance/state"

the frontend used to reflect these readings and states.

nfo: Incoming message from SmartThings: smartthings/Kitchen Motion Sensor/motion/state = active
info: Incoming message from SmartThings: smartthings/Kitchen Motion Sensor/motion/state = inactive
info: Incoming message from SmartThings: smartthings/Kitchen Motion Sensor/motion/state = active
info: Incoming message from SmartThings: smartthings/Kitchen Motion Sensor/temperature/state = 74
info: Incoming message from SmartThings: smartthings/Kitchen Motion Sensor/motion/state = inactive
info: Incoming message from SmartThings: smartthings/Master Motion Sensor/illuminance/state = 8
info: Incoming message from SmartThings: smartthings/Master Motion Sensor/motion/state = active
info: Incoming message from SmartThings: smartthings/Kitchen Motion Sensor/motion/state = active
info: Incoming message from SmartThings: smartthings/Master Motion Sensor/motion/state = inactive
info: Incoming message from SmartThings: smartthings/Kitchen Motion Sensor/motion/state = inactive
info: Incoming message from SmartThings: smartthings/Kitchen Motion Sensor/illuminance/state = 44
info: Incoming message from SmartThings: smartthings/Kitchen Motion Sensor/motion/state = active

They are still coming in, but now for motion I get clear instead of active/inactive. Never changes from clear no matter the actual state. The light sensor always had a #, now it says unknown the entire time and won’t change.

When you say “frontend” do you mean Home Assistant’s (system) log? If so, it means there’s a working connection between Home Assistant and the MQTT Broker and MQTT messages from SmartThings are getting through. That’s good news.

The bad news is none of those MQTT messages are showing up in the Lovelace UI (you reported they are either blank or Unknown).

One more thing to check, go to the States page (http://serverIPaddress:8123/dev-state) and see what it has to say about the states of sensor.kitchen_motion_sensor and sensor.kitchen_light_sensor. Do they have values or are they unknown?

Yes states pages show the same. Frontend I meant the lovelace UI