This guide assumes you already have a working and running Home Assistant server. If you don't, be sure to visit our Set up Home Assistant with a Raspberry Pi guide first.

Check Your Add-Ons

Start out by logging in and opening up your Home Assistant dashboard and checking that the File editor is installed. 

As part of the setup, you should have an add-on either called configurator or File editor with a wrench icon next to it. Go ahead and select it.

If you don't see it, it may not be installed. You can find it under Supervisor Add-on Store File editor and go through the installation procedure.

If you already have it, but it's just not showing up, be sure it is started and the option to show in the sidebar is selected.

Adding the Sensor

In order to add the Water Level Sensor to Home Assistant, you'll want to add the following code to your configuration. This will create an MQTT sensor that listens on the funhouse/catbowl/state topic. It will translate the value it recives to one of the state labels. Feel free to update the states to your liking.

sensor funhouse_catwater:
  - platform: mqtt
    name: "Cat Water Bowl"
    state_topic: "funhouse/catbowl/state"
    icon: mdi:bowl
    value_template:  >-
      {% set states =  {
          'empty' : 'Add Water',
          'low' : 'Water Low',
          'full' : 'Full'
      } %}
      {{ states[value] if value in states else 'Unknown' }}

Click the save button at the top.

If you have the Check Home Assistant configuration tool installed, now would be a good time to run it. It takes several minutes to run and you can check the log tab to see the results.

From the Configuration menu, choose Server Controls. Here you can check that the configuration is valid and click on Restart to load the configuration changes you made.

With the latest releases of Home Assistant, a LoveLace dashboard was added. If you haven't edited the Dashboard, it should automatically appear.

Otherwise, you may need to manually add a Sensor card to the dashboard.

The Cat Water Bowl sensor should appear under your sensors.

Adding Notifications

This project wouldn't be complete without having Home Assistant notify you of when the bowl gets low or empty. Home Assistant uses Persistent Notifications as its main way of notifying you, which is what we'll be showing you how to add.

Start by going to the File Editor again and click the folder icon at the top.

Open the automations.yaml file.

Add the following code. This will create 2 notification triggers. The first is when the state goes from full to low. The second is when it goes from any state to empty. Feel free to customize the messages.

- alias: "Cat Water Low"
  trigger:
  - entity_id: sensor.cat_water_bowl
    from: "full"
    platform: state
    to: "low"
  action:
    service: persistent_notification.create
    data:
      title: "Water is Low"
      message: "Cat's water is low. Consider filling it."

- alias: "Cat Water Empty"
  trigger:
  - entity_id: sensor.cat_water_bowl
    platform: state
    to: "empty"
  action:
    service: persistent_notification.create
    data:
      title: "Water is Empty"
      message: "Cat's water is empty. Fill the bowl and give your cat some love."

Once that's added, go ahead and check the configuration and restart the server as you did before. If you made changes to the water bowl code above, you may need to update this code to reflect those changes.

To test alerts, you may need to temporarily increase the UPDATE_INTERVAL in your sensor code so it checks more frequently. 

Troubleshooting

If you see the icons, but there is no data, it is easiest to start by checking the MQTT messages. Adafruit has a guide on how to use Desktop MQTT Client for Adafruit.io, which can be used for the Home Assistant MQTT server as well.

Go ahead and configure a username and password to match your MQTT server and connect. Under subscribe, you can subscribe to the # topic to get all messages.

If you are seeing messages from the sensor, you may want to double check your Home Assistant configuration.

If you don't see any messages, you will want to follow the debugging section on the Coding the Water Sensor page.

This guide was first published on May 14, 2021. It was last updated on 2021-05-14 17:06:52 -0400.

This page (Home Assistant Configuration) was last updated on Sep 18, 2021.

Text editor powered by tinymce.