Skip to content

A python script for Raspberry Pi submitting sensor data to a MQTT topic.

License

Notifications You must be signed in to change notification settings

geraldneu/PimoroniGrowKit-MQTT

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pimoroni Grow Kit - MQTT

Pimoroni's Grow Kit comes with some python samples making it possible to read the sensors data off the board. In this setup we will be reading the data and submit it to a MQTT broker channel running on a Home Assistance (HA) instance. This makes it possible to create graphs for your HA dashboard.

Requirements

Raspberry Pi Preparation

  1. Install the Raspberry Pi OS Lite image with Raspberry Pi Imager

  2. Create a SSH file in the root location of the SD card

  3. Create a wpa_supplicant.conf file in the root location of the SD card:

    country=NL
    ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
    update_config=1
    
    network={
       ssid="Wifi Network Name"
       scan_ssid=1
       psk="Wifi password"
       key_mgmt=WPA-PSK
    }
  4. Insert the SD card in the Raspberry and power it on. Connect to the raspberry via SSH and rename it to a name of your choice to easily recognize it on your network:

    # SSH connection
    ssh [email protected].**.**
        
    # Setup you Pi
    sudo raspi-config
  5. Install Pimoroni's Grow Kit python library including the examples and reboot when the installer asks for it.

    curl -sSL https://get.pimoroni.com/grow | bash
  6. Install the MQTT library

    pip3 install paho.mqtt
  7. Install the repository containing the MQTT messager

    git clone https://github.com/jeroenboumans/PimoroniGrowKit-MQTT
    cd PimoroniGrowKit-MQTT/
  8. Fill in your broker config in the config.yaml

    sudo nano config.yaml
    broker:
       port: 1883
       host: ...       # 192.168.86.x
       topic: ...      # home/livingroom/plants
    
    auth:
       username: ...   # MQTT username
       password: ...   # MQTT password
  9. Setup the Growkit MQTT watcher via the command below:

    chmod +x setup.sh
    
    ./setup.sh

Home Assistant Integration

Every Grow Kit moisture sensor needs to be registered as a sensor in Home Assistant in order to use it. To register it, use its corresponding index number: 0, 1, 2. Both moisture and saturation can be read from the topic.

To read data, register the following sensors in your Home Assistant config files:

Saturation

# sensors.yaml: sensor 1 of 3
 - platform: mqtt
   name: "Saturation"
   state_topic: "home/livingroom/plants"
   value_template: "{{ value_json.sensor_0.saturation }}"
   json_attributes_topic: " home/livingroom/plants"
   json_attributes_template: "{{ value_json.sensor_0 | tojson }}"

Moisture

# sensors.yaml: sensor 1 of 3
 - platform: mqtt
   name: "Moisture"
   state_topic: "home/livingroom/plants"
   value_template: "{{ value_json.sensor_0.moisture }}"
   json_attributes_topic: " home/livingroom/plants"
   json_attributes_template: "{{ value_json.sensor_0 | tojson }}"

Lux level (board sensor)

 - platform: mqtt
   name: "Lux"
   state_topic: "home/livingroom/plants"
   unit_of_measurement: 'Lux'
   value_template: "{{ value_json.light }}"
   json_attributes_topic: "home/livingroom/plants"
   json_attributes_template: "{{ value_json.light }}"

WHen set up you can plot the sensors in the HA dashboard using a graph like kalkih/mini-graph-card:

type: 'custom:mini-graph-card'
name: Moisture Levels
entities:
  - entity: sensor.moisture
    name: Musa
  - entity: sensor.moisture_2
    name: Herbs Mix
  - entity: sensor.moisture_3
    name: Pteris
hours_to_show: 24
line_width: 3
points_per_hour: 4
smoothing: true
color_thresholds: # range of 0 - 30 Hz for moisture
  - value: 15
    color: '#FF0000'
  - value: 5
    color: '#FFFF00'
  - value: 0
    color: '#00FFFF'
logarithmic: true
icon: 'mdi:water'
show:
  icon_adaptive_color: true
  state: true
  legend: true
  average: false
  extrema: true

About

A python script for Raspberry Pi submitting sensor data to a MQTT topic.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Shell 56.4%
  • Python 43.6%