Re-doing my MQTT for the breaking changes

Looking for some advice on how to configure my YAML for the MQTT breaking changes. This is my only manually configured MQTT thing and all it does is trick my home into thinking someone is home even when all devices have left (guest mode). If there’s a cleaner way to do this and get away from it altogether, I’m all ears.

What I currently have:

device_tracker:
  platform: mqtt
  devices:
    guest: 'location/guest'
switch:
  - platform: mqtt
    name: "Guest Mode"
    command_topic: "location/guest"
    payload_on: "home"
    payload_off: "away"
    retain: true

And what I plan to change it to:

mqtt:
  devices:
    guest: 'location/guest'
  switch:
    unique_id: guest_mode
    name: "Guest Mode
    command_topic: "location/guest"
    payload_on: "home"
    payload_off: "away"
    retain: true

I got this reply to a Reddit thread, but I’m afraid I don’t fully understand what it means:

Are you in control of the command topic at all? If you start the topic with homassistant/switch, HA should automatically discover it and you won’t even need that config

Edit:

I have this automation in Node Red, so thinking more about it I can just delete this MQTT stuff and create a helper switch, and have NR check if the switch is on or off before actioning the following nodes, no? I set this up with community help as one of the first things I did when I got HA, and now that it’s been a long time details are fuzzy as to why I did things the way I did.

Edit 2!:

This is my template for the home group. Couldn’t I just edit this to include the state of the input boolean I create, then I could do away with the check in NR as well? Proposed YAML below:

- platform: template
  sensors:
    is_someone_home:
      friendly_name: "Is Someone Home"
      value_template: >
        {% set husband_state = states('person.husband') %}
        {% set wife_state = states('person.wife') %}
        {% set boy_state = states('person.boy') %}
        {% set guest_state = states('input.boolean.guest_mode) %}
        {% if husband_state == 'home' or wife_state == 'home' or boy_state == 'home' or guest_state == 'on' %}
          yes
        {% elif husband_state == 'not_home' and wife_state == 'not_home' and boy_state == 'not_home' and guest_state == 'off' %}
          no
        {% else %}
          Unknown
        {% endif %}

If all you need is a switch whose state turns on/off automations, then an input_boolean Helper may be cleaner. These can be created via the GUI (Settings → Devices & Services → Helpers) or via configuration.yaml

Your proposed config needs at least one change - unique_id is now for the GUI to create a UUID, rather than a textural name (replaced by text generated from name). Beyond that, HASS is a better syntax checker than me!

As for switching automations, all you need is a condition, which are easier to create from the GUI

 condition:
  - condition: state
    entity_id: input_boolean.guest_mode
    state: 'away'

If this helps, :heart: this post!