Mastering Advanced Power Monitoring: Integrating Shelly Devices with Home Assistant's Energy Dashboard for Granular Insights and Cost Optimization
NGC 224
DIY Smart Home Creator
Mastering Advanced Power Monitoring: Integrating Shelly Devices with Home Assistant's Energy Dashboard for Granular Insights and Cost Optimization
Are you tired of skyrocketing electricity bills with no clear understanding of where your energy goes? Standard smart plugs offer basic on/off control, but lack the precision needed for true energy optimization. Without granular data, identifying energy hogs or understanding usage patterns across your entire home is a challenge. This often leads to missed opportunities for significant cost savings and a less efficient smart home.
The solution lies in robust, local power monitoring devices like Shelly, seamlessly integrated with Home Assistant's powerful Energy Dashboard. Shelly devices, renowned for their accuracy, local control capabilities, and open API (CoIoT/MQTT), offer a versatile range from individual appliance monitoring (Shelly Plug S) to whole-house consumption tracking (Shelly EM, Shelly 3EM). By combining these with Home Assistant, you gain a dynamic, real-time overview of your energy footprint, empowering you to make informed decisions, automate energy-saving routines, and significantly reduce your utility bills.
This guide will walk you through integrating Shelly devices for advanced power monitoring, optimizing them for Home Assistant's Energy Dashboard, and leveraging this data for smarter, more cost-efficient automations. Whether you're a tech enthusiast, a practical homeowner, or a professional integrator, prepare to unlock unprecedented control over your home's energy consumption.
Step-by-Step Setup: Integrating Shelly EM/3EM for Whole-Home Monitoring
This section focuses on integrating Shelly EM or 3EM for main circuit monitoring, a foundational step for comprehensive energy tracking.
1. Initial Shelly Device Setup
Before integrating with Home Assistant, your Shelly device needs to be connected to your local Wi-Fi network and updated.
- Power On and Connect to AP: Install your Shelly EM/3EM according to the manufacturer's instructions (always consult a qualified electrician for main circuit installations). Once powered, it will emit an open Wi-Fi access point (e.g.,
shellyem-XXXXXX). Connect to this network from your phone or computer. - Access Web UI: Open a web browser and navigate to
192.168.33.1. This is the Shelly device's local configuration page. - Connect to Home Wi-Fi: Go to 'Internet & Security' -> 'Wi-Fi Mode - Client'. Enter your home Wi-Fi SSID and password, then save. The device will restart and connect to your network. Note its new IP address from your router or a network scanner.
- Update Firmware: Access the device's web UI via its new IP address. Navigate to 'Settings' -> 'Firmware Update' and install the latest stable version. This ensures compatibility and security.
- Enable CoIoT (Recommended for Easy HA Integration): For seamless auto-discovery in Home Assistant, enable CoIoT. In the Shelly web UI, go to 'Internet & Security' -> 'CoIoT'. Ensure 'Enable CoIoT' is checked. If your Home Assistant is on a different VLAN, you might need to ensure multicast routing is properly configured between them, or consider using MQTT instead (covered in 'Advanced Configuration').
2. Home Assistant Integration (CoIoT via Auto-Discovery)
With CoIoT enabled and your Shelly on the network, Home Assistant should typically discover it automatically.
- Check for Discovery: In Home Assistant, navigate to
Settings->Devices & Services->Integrations. Look for a 'Discovered' card for Shelly. - Add Integration: If discovered, click
Configure. If not, clickAdd Integrationin the bottom right, search for 'Shelly', and follow the prompts. - Complete Setup: Home Assistant will prompt you for the device's IP address (if not auto-discovered) and may ask for a device name or area. Once completed, Home Assistant will create entities for consumption (e.g.,
sensor.shelly_em_channel_a_energy_wh), voltage, and current for each channel.
3. Configuring for Home Assistant Energy Dashboard
The Energy Dashboard requires specific sensor attributes to correctly display consumption data. The most critical attributes are state_class: total_increasing, unit_of_measurement: kWh, and device_class: energy.
- Access Energy Dashboard Settings: In Home Assistant, go to
Settings->Dashboards->Energy. - Add Electricity Grid Source: Under 'Electricity grid', click 'Add consumption'.
- Select Shelly Energy Sensors: Look for your Shelly's energy sensors (e.g.,
sensor.shelly_em_channel_a_energy_wh). Home Assistant will often automatically detect and convert these if they report in Wh. If your sensor's unit is already kWh and has the correct state attributes, it will appear directly. - Verify Sensor Attributes (if needed): If your Shelly energy sensor doesn't appear or reports incorrectly, verify its attributes. Go to
Developer Tools->States, find your Shelly energy sensor, and check itsstate_class,unit_of_measurement, anddevice_class. - Template Sensor for Conversion/Correction: If the unit is Wh and Home Assistant doesn't automatically convert, or if attributes are missing, you can create a template sensor in your
configuration.yaml. This example converts Wh to kWh and sets the correct attributes:
# configuration.yaml template: - sensor: - name: "Shelly EM Main Energy Total kWh" unique_id: shelly_em_main_energy_total_kwh unit_of_measurement: "kWh" device_class: "energy" state_class: "total_increasing" state: "{{ (states('sensor.shelly_em_total_energy_wh') | float / 1000) | round(2) }}" # Replace 'sensor.shelly_em_total_energy_wh' with your actual Shelly total energy sensor availability: "{{ states('sensor.shelly_em_total_energy_wh') | is_number }}"After adding this, restart Home Assistant and add the new
sensor.shelly_em_main_energy_total_kwhto your Energy Dashboard. - Add Individual Device Consumption: For devices monitored by Shelly Plug S or other individual Shelly relays with power metering, repeat step 3 for 'Individual devices'. Ensure their `_energy_wh` or `_energy_kwh` sensors have the correct attributes.
Troubleshooting Common Issues
Even with straightforward integrations, hiccups can occur. Here are solutions for frequent problems:
Device Not Discovered / Unavailable
- Network Connectivity: Ensure your Shelly device is powered on and connected to the same Wi-Fi network (and subnet) as your Home Assistant instance. Ping the Shelly's IP address from your Home Assistant host to confirm network reachability.
- CoIoT Status: Double-check that CoIoT is enabled in the Shelly's web UI ('Internet & Security' -> 'CoIoT').
- Multicast Routing (VLANs): If Home Assistant and Shelly are on different VLANs, multicast (which CoIoT relies on) might be blocked. Configure your router/switch to allow multicast traffic between the VLANs, or consider switching to MQTT (see 'Advanced Configuration').
- Firewall Rules: Ensure no firewall on your Home Assistant host or network is blocking UDP port 5683 (CoIoT) or TCP port 1883 (MQTT) if using MQTT.
- Restart HA: Sometimes, a simple Home Assistant restart can trigger discovery.
Energy Dashboard Data Missing or Incorrect
- Sensor Attributes: This is the most common issue. The Energy Dashboard strictly requires sensors with
state_class: total_increasing,unit_of_measurement: kWh, anddevice_class: energy. UseDeveloper Tools->Statesto inspect your sensors. If attributes are missing or incorrect, use a template sensor as shown in the setup steps to correct them. - Cumulative Energy vs. Instantaneous Power: The dashboard needs *total accumulated energy* (e.g.,
_energy_wh,_energy_kwh), not instantaneous power (e.g.,_power). Ensure you've selected the correct sensor type. - Data Accumulation: The Energy Dashboard processes data hourly. After adding new sensors, it might take an hour or two for initial data to appear. Don't expect instant graphs.
- Historical Data: If you're using a new sensor, there won't be historical data for it. Graphs will start populating from the point it was correctly configured.
CoIoT vs. MQTT: When to Choose Which
- CoIoT: Simpler for initial setup due to auto-discovery. Ideal for networks where Home Assistant and Shelly devices are on the same subnet and multicast is functional. Less configuration overhead.
- MQTT: More robust and flexible. Recommended for larger networks, setups with VLANs, or when you need finer control over message delivery (e.g., QoS settings). It requires an MQTT broker (like Mosquitto, available as an add-on in Home Assistant OS). MQTT offers greater resilience against network discovery issues and provides a centralized message bus for all your IoT devices.
Advanced Configuration and Optimization
Push your energy monitoring further with MQTT, data filtering, and intelligent automations.
MQTT for Reliability and Customization
While CoIoT is convenient, MQTT provides a more robust and customizable communication layer. If you have an MQTT broker set up (e.g., Mosquitto add-on), consider configuring your Shelly devices to use it.
- Configure Shelly for MQTT: In the Shelly device's web UI, go to 'Internet & Security' -> 'Advanced - Developer Settings'. Enable 'Enable MQTT' and provide your MQTT broker's IP address and port (default 1883), along with a username and password if required. Set a 'Custom MQTT Prefix' for organization (e.g.,
shelly/myhome/mainem). - Home Assistant MQTT Integration: Ensure Home Assistant's MQTT integration is configured to connect to your broker. It can auto-discover Shelly devices publishing via MQTT if the topics adhere to standard formats.
- Manual MQTT Sensor Definition (Optional, for Customization): If auto-discovery isn't preferred or for specific customizations, you can define MQTT sensors manually in your
configuration.yaml. This gives you absolute control over attributes and value parsing.# configuration.yaml mqtt: sensor: - name: "Shelly EM Main Consumption Power" state_topic: "shellies/shellyem-XXXXXX/em/0/power" # Adjust topic to your Shelly's unit_of_measurement: "W" device_class: "power" state_class: "measurement" # For instantaneous power value_template: "{{ value | float }}" availability_topic: "shellies/shellyem-XXXXXX/online" payload_available: "true" payload_not_available: "false" - name: "Shelly EM Main Energy Total (MQTT)" state_topic: "shellies/shellyem-XXXXXX/em/0/energy" # This topic usually reports in Wh unit_of_measurement: "kWh" device_class: "energy" state_class: "total_increasing" value_template: "{{ (value | float / 1000) | round(2) }}" # Convert Wh to kWh availability_topic: "shellies/shellyem-XXXXXX/online" payload_available: "true" payload_not_available: "false"Remember to replace
shellies/shellyem-XXXXXXwith your Shelly's actual MQTT topic prefix.
Filtering Data and Utility Meters
- Filter Sensors: For noisy power sensors, a
filtersensor can smooth out readings, making graphs cleaner and automations more reliable. For example, athrottlefilter can reduce update frequency, or anoutlierfilter can remove erroneous spikes.# configuration.yaml sensor: - platform: filter name: "Smoothed Main Power" entity_id: sensor.shelly_em_main_consumption_power # Your raw power sensor filters: - filter: throttle window_size: 10 precision: 0 - Utility Meter: To track daily, weekly, monthly, or yearly consumption resets (useful for aligning with billing cycles), use Home Assistant's
utility_meterintegration. This creates new sensors that reset at defined intervals based on your primary energy sensor.# configuration.yaml utility_meter: daily_grid_consumption: source: sensor.shelly_em_main_energy_total_kwh # Your primary kWh sensor cycle: daily monthly_grid_consumption: source: sensor.shelly_em_main_energy_total_kwh cycle: monthly
Automating with Energy Data
The true power of granular monitoring is the ability to create intelligent automations.
- Load Shedding: Turn off non-essential devices if total grid consumption exceeds a pre-defined threshold. This is crucial for homes with solar or limited grid capacity.
# automation.yaml - alias: "Automate Load Shedding for High Consumption" trigger: - platform: numeric_state entity_id: sensor.shelly_em_main_consumption_power above: 5000 # Trigger if consumption is above 5000W for: "00:01:00" # For at least 1 minute condition: - condition: time before: "22:00:00" after: "08:00:00" # Only during peak hours action: - service: switch.turn_off target: entity_id: switch.washer_machine_power # Example high-draw appliance - service: notify.mobile_app_your_device data: message: "High energy consumption detected. Washer machine turned off temporarily." - Abnormal Usage Alerts: Receive notifications if a specific appliance's energy usage is outside its typical pattern (e.g., fridge running too frequently, indicating a potential fault).
# automation.yaml - alias: "Alert on Abnormal Fridge Consumption" trigger: - platform: state entity_id: sensor.shelly_plug_s_fridge_energy_kwh # Example fridge energy sensor condition: - condition: template value_template: "{{ (state_attr('sensor.shelly_plug_s_fridge_energy_kwh', 'last_period_consumption') | float > 2.0) and (now().hour > 6 and now().hour < 22) }}" # More than 2kWh in a day, during active hours action: - service: notify.mobile_app_your_device data: message: "Abnormally high fridge energy usage detected today! Check for issues."
Real-World Example: Optimizing Electric Vehicle Charging with Dynamic Load Balancing
Consider a scenario where you have a Shelly 3EM monitoring your whole-house consumption, and a dedicated Shelly EM or Plug S monitoring your Electric Vehicle (EV) charger's consumption. Your goal is to maximize EV charging while ensuring you don't exceed your grid's capacity or incur peak-hour surcharges.
Setup:
- Whole-House Monitoring:
sensor.shelly_3em_total_power(instantaneous total power in Watts). - EV Charger Monitoring:
sensor.shelly_em_ev_charger_power(instantaneous power of the EV charger). - EV Charger Control: A smart switch (e.g., another Shelly relay or a dedicated EVSE integration) that can turn the charger on/off:
switch.ev_charger_relay. - User-Defined Limit: An
input_numberhelper in Home Assistant to set a maximum desired household power consumption (e.g., 8000W).# configuration.yaml input_number: max_house_power_limit: name: "Max House Power Limit (W)" initial: 8000 min: 1000 max: 15000 step: 100 unit_of_measurement: "W" mode: slider
Automation Logic:
Create two automations:
- Pause EV Charging if Over Limit: When total house power minus EV charger power exceeds a set limit, turn off the EV charger.
- Resume EV Charging if Under Limit: When total house power minus EV charger power drops significantly below the limit, turn on the EV charger (if it was previously paused and EV needs charging).
Example Automation (Pause Charging):
# automation.yaml
- alias: "EV Charger Pause on High House Load"
trigger:
- platform: numeric_state
entity_id: sensor.shelly_3em_total_power
above: "{{ states('input_number.max_house_power_limit') | float }}"
for: "00:00:30" # Sustain high load for 30 seconds before pausing
condition:
- condition: state
entity_id: switch.ev_charger_relay
state: "on" # Only if charger is currently on
- condition: numeric_state
entity_id: sensor.shelly_em_ev_charger_power
above: 100 # Ensure EV is actually drawing power
action:
- service: switch.turn_off
target:
entity_id: switch.ev_charger_relay
- service: notify.mobile_app_your_device
data:
message: "EV charging paused due to high household power consumption ({{ states('sensor.shelly_3em_total_power') | round(0) }}W)."
This dynamic load balancing ensures that your EV charges efficiently without overloading your electrical system or causing unnecessary spikes during peak demand, saving you money and ensuring system stability.
Best Practices and Wrap-up
To ensure your advanced power monitoring setup is secure, reliable, and provides long-term value, follow these best practices:
- Security: Isolate all IoT devices, including Shelly, on a separate VLAN. Use strong, unique Wi-Fi passwords. Keep Shelly device firmware and Home Assistant updated to benefit from the latest security patches.
- Reliability: A stable Wi-Fi network is paramount. For critical applications or complex networks, MQTT generally offers more robust communication than CoIoT due to its message queuing and persistent connection capabilities. Ensure your MQTT broker is also reliable.
- Data Integrity: Regularly back up your Home Assistant configuration (full snapshots are ideal). Understand the significance of
state_class: total_increasinganddevice_class: energyfor accurate Energy Dashboard reporting; incorrect attributes are the leading cause of dashboard issues. - Maintenance: Periodically check the web UI of your Shelly devices to ensure they are online, updated, and reporting correctly. Monitor Home Assistant logs for any integration errors related to Shelly.
- Scalability: Shelly's ecosystem is highly scalable. You can easily add more Shelly devices (Plug S for individual appliances, EM for sub-circuits) to gain even finer-grained insights without overhauling your existing setup.
By implementing these advanced power monitoring techniques with Shelly devices and Home Assistant's Energy Dashboard, you're not just tracking consumption; you're gaining a powerful tool for understanding, optimizing, and ultimately reducing your home's energy footprint. This proactive approach empowers you to save money, contribute to environmental sustainability, and build a truly intelligent and efficient smart home.
NGC 224
Author bio: DIY Smart Home Creator
