Gude Systems PDU 8035 series integration via MQTT: Part 1 - Introduction

Gude Systems PDU 8035 series integration via MQTT: Part 1 - Introduction

This project is about connecting a PDU to Home Assistant by using a MQTT Discovery script and allow Home Assistant to control the PDU. In doing so, I hope it can also serve others.
Sorry that this is a long post.

I needed to split this article up five parts:

What is a PDU and why use it?
PDU stands for Power Distribution Unit. Simply put: you use a PDU to power on devices in a certain fixed order. You might want this for example when the electricity turns back on after a power failure on the utility grid and you want to make sure that your router and internet connection is up, before starting up your Home Assistant computer.

By using a MQTT discovery script, an automation and an input.boolean variable, this PDU can be discovered via MQTT and added automatically when HA starts. I also made a simple dashboard in Home Assistant.

Below a partial picture of the PDU in MQTT

Compatibility with other Gude PDUs
The discovery script is designed for a Gude Systems 8035 series 8-fold switched and outlet-metered PDU, but it can easily be adapted to the 8031 series. The difference between the two is the 8035 also measures voltage, current and power per outlet. If you disable the per outlet current and per outlet power in my script, you can use the script also for the 8031 series PDU. The discovery script is a collection of building blocks to make adapting the script easier for the other PDU models of Gude Systems, since – at first sight – they only differ on the amount of ports and per outlet measurements. Gude Systems is a German manufacturer.

The dashboard

The dashboard is intentionally simple and consists of three main sections: Line In, Outlets, and Maintenance.

Below is a picture of the PDU dashboard

Line in section
Column 1 through 3 shows line voltage, total current, and power.
Column 4 shows the boolean state of variable pdu_mqtt_telemetry_received. You can press the envelope icon when you want the MQTT discovery script run again, for instance when dashboard data gives rubbish.
Column 5 enable you power cycle all outlets. All outlets are switched off from outlet 8 trough 1, and are turned on respecting the cold start delay defined in de PDU for each outlet.

Outlets section
This section shows per outlet:

  • the outlet state (on/off),
  • the outlet label as defined in the PDU. Labels are extracted from the telemetry data so it is one way: PDU > HA.
  • power and current
  • option to power cycle this outlet. To ensure that a switched power supply lasts longer, a power cycled outlet stays out for 30 seconds before turning it back on.

When an outlet is switched off, only outlet number, outlet and label is shown.
The state of each outlet is synced.

Maintenance section
Column 4 shows the boolean state of variable pdu_mqtt_telemetry_received. You can press the envelope icon when you want the MQTT discovery script run again, for instance when dashboard data gives rubbish. Since we rely on telemetry data, it is important to see if telemetry data is received.
Column 3 enables you to reboot the PDU. In my test lab, I discovered that the PDU sometimes did not send telemetry data anymore (probably because I messed around too much). The only remedy was to reboot the PDU. For the Gude Systems 8035 series PDU, this means that the OS reboots, but the state of the outlets remains unchanged. A great feature!

How does it all work?

I assume you use the default mqtt broker that comes with HA.
The PDU connects to the mqtt broker, and publishes each 60 seconds telemetry data on a mqtt topic (in my case) de/gudesystems/epc/00:19:32:02:4f:40/device/telemetry.

The automation script will be triggered when something is published on this mqtt topic, and check if the input.boolean variable pdu_mqtt_telemetry_received is set or not. If not, it will set the pdu_mqtt_telemetry_received variable to true and execute the MQTT Discovery script that defines our PDU in HA via MQTT Discovery.

Afterwards, the automation script will still be triggered when a message is received on mqtt topic de/gudesystems/epc/00:19:32:02:4f:40/device/telemetry, but it won’t execute the MQTT discovery script because the input.boolean variable pdu_mqtt_telemetry_received is set to true.
Because MQTT discovery devices are not remembered by HA after a reboot, this variable is set to false each time when HA starts, so my discovery script is executed automatically when HA is started and the PDU has checked in.

What you need

Before you start

  • Make sure your MQTT integration and broker are set up in Home Assistant and works.
  • Home Assistant is using MQTT over tcp. Make sure Home Assistant and the PDU can “see” each other (try pinging).
  • Since MQTT communication (in this case) is not encrypted, it is best that you put the PDU – together with your Home Assistant – on a separate network segment and restrict access to that network segment.
  • Make sure the PDU and Home Assistant have a fixed ip address. In my test lab, I used an ipv4 address, but you can use also an ipv6 address. For the latter, I suggest you use your link local (fe80…) address.

The MQTT discovery script
To script that defines the 8035 by using MQTT discovery, is actually a script bundle. I did this to make it easier for others to test and adapt the script.

Devices that are added via MQTT discovery, are forgotten by HA upon reboot. Also, when you would power on the PDU after HA is started, the PDU would not be seen by HA. My quick fix solution for this is to make:

  • an automation script to execute my MQTT discovery script bundle when the PDU is “alive” by sending telemetry data.
  • a variable to keep record if telemetry data is received from the PDU. When this variable is set, it also prevents the automation script to re-execute my MQTT discovery script. This has another advantage: by resetting this variable, you can re-execute the MQTT discovery script again when needed.

I rely on the telemetry data the PDU sends each 60 seconds, to

  • know the PDU is alive,
  • to get information in regard to power, voltage, current and port labels.

Special thanks

Getting this all worked out took me about a month fulltime. I never worked with mqtt and never wrote scripts in HA. I could not have done it with the help of AI (mostly Mistral AI and sometimes ChatGPT). Even when the suggested codes by AI was often wrong, it helped me pointing in the right direction. I also like to thank community member Didgeridrew and others who helped me pointing in the right direction when I was really stuck on a fundamental coding part.
I also like to thank Gude Systems for their excellent technical documentation https://wiki.gude-systems.com/MQTT_eng in regard to mqtt and what commands are available for cli via mqtt.

Johan

Gude Systems PDU 8035 series integration via MQTT: Part 2 - Preparation

Look for the main article at Gude Systems PDU 8035 series integration via MQTT: Part 1 - Introduction

Preparation

Step 1 - Get your mqtt broker details

I assume you use the mqtt broker that comes with HA.

Get the:

  • ip address of the mqtt broker (normally the ip address of your HA),
  • mqtt username and password that you and HA are using to login to the mqtt broker.

If you panic on that one, watch this instruction on YouTube https://youtu.be/sfsZF0R0HtE.

Step 2 - PDU: configure mqtt

  1. Login to the WebGUI of your PDU, click on the tab Configuration > Protocols > MQTT
    At least fill in:
  2. Broker: the ip address of your broker instance,
  3. TCP port: (leave default),
  4. Username: your mqtt username,
  5. Set new password: the password of your mqtt user,
    repeat password: same as above,
  6. Topic Prefix: stick to de/gudesystems/epc/[mac],
    (write down the mac address that is shown here. You need it later),
  7. Permit CLI commands: yes,
    Very important since HA will control the PDU by using cli commands,
  8. Publish device data summary interval: 60
    (In my case this means that each 60 seconds telemetry data is published on mqtt topic de/gudesystems/epc/00:19:32:02:4f:40).

Click on Apply to save this configuration.

When you are here, also make note of the ip address of your PDU.

Check your connection

Now would be a good time to check if your PDU is able to connect to your mqtt broker by using – for instance – the MQTT Explorer (More information on how to get, install and use the MQTT Explorer in HA can be found here https://community.home-assistant.io/t/addon-mqtt-explorer-new-version/603739).

When your PDU is able to connect, you see in MQTT Explorer a topic called de/gudesystems/epc/[mac]/device/telemetry, in my case de/gudesystems/epc/00:19:32:02:4f:40/device/telemetry.

If you don’t see this after two minutes or so, you need to start troubleshooting before you can continue.

Step 2b - PDU: Check your Power Port label and delay settings

In the WebGUI of your PDU, go to Configuration > Power Ports. Here, I can set parameters on a per port base of the 8035 PDU as shown below.

You can set the label of a port (a description that makes sense to you), but more important is the Coldstart section. Coldstart means: “when the PDU boots, what will happen with this outlet and when?”. In the picture shown here, the outlet will be turned on 35 seconds after the PDU is ready after a boot.

Coldstart delay (2) vs Reset action duration (3)

When the PDU is powered on, the Coldstart delay (2) is used to delay an action that is set in Coldstart status for a port.
When a port is power cycled, the Reset action duration (3) is used to switch on a port again.

How to calculate values (2) and (3)?

My script sets the Reset action duration (3) value automatically for each port. The Coldstart delay (2), you have to set yourself. To calculate the value for Coldstart delay: determine the time in seconds after an outlet has to be turned on + 30 seconds (see text below why).

Most network equipment use a switched power supply. Switched power supplies don’t like to be switched off and immediately turn back on. This is due capacitors inside a switched power supply that are not yet discharged enough. As a rule of thumb, wait 30 seconds before turning of a switched power supply after it has switched off.

Step 3 - Before you can use the MQTT discovery script,

You need to change a few things before you can use my script code for your PDU.
Things that need to be changed are:

  • ip address of the PDU
  • mac address of the PDU

Get my script code (see part 3) and copy and paste it in your favorite text or YAML editor.

Get the ip and mac address of your PDU that you wrote down in step 2.
Write the mac address of your PDU in two formats:
like this: 001932024f40
and like this: 00:19:32:02:4f:40.

To replace, open my MQTT script in Home Assistant, switch to Edit in YAML, and, in your favorite text editor, find and replace this 001932024f40 and this 00:19:32:02:4f:40 by yours.

Get the ip address your PDU has. Find and replace http://10.10.10.91 with your ip address.

If you use a different device

If your PDU has a different amount of ports, look in my script for
for_each: "{{ range(1,9) | list}}"

and change 9 to the number of ports + 1.
For example: the 8035 has 8 outlets, so 8 + 1 = 9

If your PDU does not have the per port power and current feature, simply disable the script sections Define Sensors - Per outlet (1 through 8): Power measurement and Define Sensors - Per outlet (1 through 8): Current measurement.

Step 3b Install the script in HA

In HA go to Settings > Automations & scenes > Scripts, click on Create script and select Create new script.
Click on the three dots and select Edit in YAML from the submenu.

Copy and paste the altered script code form your editor to HA.

Save the script and your are done.

Check and troubleshoot the script

The script is set up as a script bundle that bundles different actions together. When you click on the three dots right of an action, you can select run action to see if the action runs successfully.

When you go in HA to Settings > Devices & services > Integrations > MQTT, you normally will see your PDU appear. When you click on your PDU, you see the entities that are created so far.

Step 4 - Create an input.boolean variable

You can create input.boolean variables in the GUI, but you can’t set the initial value in the UI, hence I create this in configuration.yaml of HA.

Open the configuration.yaml of HA (I use Studio Code Server) and add the code below

  pdu_mqtt_telemetry_received:
    name: PDU MQTT telemetry received
    initial: false
    icon: mdi:email-open-outline

Save the file and check via HA > Developer Tools > Check configuration if your configuration.yaml prevent HA from starting.

While you are there, you can announce this variable to HA by clicking on Input booleans under YAML configuration reloading, or just reboot HA.

Step 5 - Before you can use the automation script

Modifying the automation script goes in the same way as for the script in step 3. Copy and paste my script code (see part 4) in your favorite text or YAML editor. Search and replace for 00:19:32:02:4f:40 and replace it with the mac address of your device.

Step 5b Install the automation in HA

In HA go to Settings > Automations & scenes > Automations and click on Create automation and select Create new automation.
Click on the three dots and select Edit in YAML from the submenu. Copy and paste the altered script code form your editor to HA. Save the script and your are done.

Step 6 - Before you can use the PDU dashboard

For some reason, power measurement sensor for outlet 1 is called sensor.none_pdu_outlet_1_power, while it should be sensor.pdu_8035_3_r2_pdu_outlet_1_power.

Since I don’t have enough experience as a developer, I don’t know what causes this naming artifact. When the power reading for outlet 1 is unknown, you now know what to change.

Step 6b - Add the PDU dashboard to HA

In HA go to Settings > Dashboards click on Add dashboard and select New dashboard from scratch.

As Title, use PDU (or something else)
Select Admin only and Add to sidebar.
Confirm by clicking on Create.

Open dashboard, click on the pencil icon top right and then on the three dots. Select raw configuration editor from the submenu.

Copy and paste my dashboard code (see part 5 here and click on save.

A note in regard to the dashboard code
The complete dashboard code is too large to fit into an article on this forum, hence the code provided is a trimmed version: it is complete, except for outlets 3 through 8. Getting those is simply a matter af duplicating outlet 2 and adapt number of each entry id.

if you use a PDU without per port power and current measurement, you can delete column 3 and 4 altogether of an horizontal stack that I used per outlet.

Gude Systems PDU 8035 series integration via MQTT: Part 3 - The MQTT Discovery script code

Look for the main article at Gude Systems PDU 8035 series integration via MQTT: Part 1 - Introduction

The MQTT Discovery script code

  - alias: "Define Button: PDU Reboot"
    action: mqtt.publish
    metadata: {}
    data:
      qos: "0"
      topic: homeassistant/button/pdu_001932024f40/system_restart/config
      payload: |-
        {%raw%}{
          "name": "PDU Reboot",
          "unique_id": "pdu_001932024f40_system_reboot",
          "command_topic": "de/gudesystems/epc/00:19:32:02:4f:40/cmd/cli",
          "payload_press": "system restart",
          "icon": "mdi:refresh",
          "device": {
            "identifiers": ["pdu_001932024f40"]
          }
        }{%endraw%}
  - delay:
      hours: 0
      minutes: 0
      seconds: 0
      milliseconds: 800
  - alias: "Define Switches - Per outlet (1 through 8): Switch"
    repeat:
      for_each: "{{ range(1,9) | list}}"
      sequence:
        - action: mqtt.publish
          metadata: {}
          data:
            qos: "0"
            retain: true
            topic: >-
              homeassistant/switch/pdu_001932024f40/outlet_{{ repeat.item
              }}/config
            payload: |-
              {%raw%}{
                "name": "PDU Outlet {%endraw%}{{ repeat.item }}{%raw%}",
                "unique_id": "pdu_001932024f40_outlet_{%endraw%}{{ repeat.item }}{%raw%}",
                "command_topic": "de/gudesystems/epc/00:19:32:02:4f:40/cmd/cli",
                "payload_on": "port {%endraw%}{{ repeat.item }}{%raw%} state set 1",
                "payload_off": "port {%endraw%}{{ repeat.item }}{%raw%} state set 0",
                "state_topic": "de/gudesystems/epc/00:19:32:02:4f:40/switch/{%endraw%}{{ repeat.item }}{%raw%}",
                "value_template": "{{ value_json.state }}",
                "state_on": "1",
                "state_off": "0",
                "availability": {
                  "topic": "de/gudesystems/epc/00:19:32:02:4f:40/device/telemetry",
                  "value_template": "{{ 'type' in value_json }}",
                  "payload_available": true,
                  "payload_not_available": false
                },
                "icon": "mdi:power-socket-de",
                "device": {
                  "identifiers": ["pdu_001932024f40"],
                  "name": "PDU 8035-3 R2",
                  "manufacturer": "Gude Systems GmbH",
                  "model": "Expert Power Control 8035-3 R2",
                  "hw_version": "8035 R2",
                  "configuration_url": "http://10.10.10.91"
                }
              }{%endraw%}
        - delay:
            hours: 0
            minutes: 0
            seconds: 0
            milliseconds: 800
    enabled: true
  - alias: "Define Sensors - Per outlet (1 through 8): Outlet Label"
    repeat:
      for_each: "{{ range(1,9) | list}}"
      sequence:
        - action: mqtt.publish
          metadata: {}
          data:
            qos: "0"
            retain: true
            topic: >-
              homeassistant/sensor/pdu_001932024f40/outlet_{{ repeat.item
              }}_label/config
            payload: |-
              {%raw%}{
                "name": "PDU Outlet {%endraw%}{{ repeat.item }}{%raw%} Label",
                "unique_id": "pdu_001932024f40_outlet_{%endraw%}{{ repeat.item }}{%raw%}_label",
                "state_topic": "de/gudesystems/epc/00:19:32:02:4f:40/device/telemetry",
                "value_template": "{{ value_json.portstates[({%endraw%}{{repeat.item}}{%raw%} | int -1)].name }}",
                "device": {
                "identifiers": ["pdu_001932024f40"]
                }
              }{%endraw%}
        - delay:
            hours: 0
            minutes: 0
            seconds: 0
            milliseconds: 800
    enabled: true
  - alias: "Define Sensors - Per outlet (1 through 8): Power measurement"
    repeat:
      for_each: "{{ range(1,9) | list}}"
      sequence:
        - action: mqtt.publish
          metadata: {}
          data:
            qos: "0"
            retain: true
            topic: >-
              homeassistant/sensor/pdu_001932024f40/outlet_{{ repeat.item
              }}_power/config
            payload: |-
              {%raw%}{
                "name": "PDU Outlet {%endraw%}{{ repeat.item }}{%raw%} Power",
                "unique_id": "pdu_001932024f40_outlet_{%endraw%}{{ repeat.item }}{%raw%}_power",
                "state_topic": "de/gudesystems/epc/00:19:32:02:4f:40/device/telemetry",
                "value_template": "{{ value_json.outlets[({%endraw%}{{repeat.item}}{%raw%} | int -1)].act_pow }}",
                "state_class": "measurement",
                "device_class": "power",
                "unit_of_measurement": "W",
                "availability": {
                  "topic": "de/gudesystems/epc/00:19:32:02:4f:40/device/telemetry",
                  "value_template": "{{ 'type' in value_json }}",
                  "payload_available": true,
                  "payload_not_available": false
                },
                "device": {
                "identifiers": ["pdu_001932024f40"]
                }
              }{%endraw%}
        - delay:
            hours: 0
            minutes: 0
            seconds: 0
            milliseconds: 800
    enabled: true
  - alias: "Define Sensors - Per outlet (1 through 8): Current measurement"
    repeat:
      for_each: "{{ range(1,9) | list}}"
      sequence:
        - action: mqtt.publish
          metadata: {}
          data:
            qos: "0"
            retain: true
            topic: >-
              homeassistant/sensor/pdu_001932024f40/outlet_{{ repeat.item
              }}_current/config
            payload: |-
              {%raw%}{
                "name": "PDU Outlet {%endraw%}{{ repeat.item }}{%raw%} Current",
                "unique_id": "pdu_001932024f40_outlet_{%endraw%}{{ repeat.item }}{%raw%}_current",
                "state_topic": "de/gudesystems/epc/00:19:32:02:4f:40/device/telemetry",
                "value_template": "{{ value_json.outlets[({%endraw%}{{repeat.item}}{%raw%} | int -1)].current }}",
                "state_class": "measurement",
                "device_class": "current",
                "unit_of_measurement": "A",
                "availability": {
                  "topic": "de/gudesystems/epc/00:19:32:02:4f:40/device/telemetry",
                  "value_template": "{{ 'type' in value_json }}",
                  "payload_available": true,
                  "payload_not_available": false
                },
                "device": {
                "identifiers": ["pdu_001932024f40"]
                }
              }{%endraw%}
        - delay:
            hours: 0
            minutes: 0
            seconds: 0
            milliseconds: 800
    enabled: true
  - alias: "Define Sensor: Line Voltage measurement"
    action: mqtt.publish
    metadata: {}
    data:
      qos: "0"
      retain: false
      topic: homeassistant/sensor/pdu_001932024f40/line_voltage/config
      payload: |-
        {%raw%}{
          "name": "PDU Line Voltage",
          "unique_id": "pdu_001932024f40_line_voltage",
          "state_topic": "de/gudesystems/epc/00:19:32:02:4f:40/device/telemetry",
          "value_template": "{{ value_json.line_in[0].voltage }}",
          "state_class": "measurement",
          "device_class": "voltage",
          "unit_of_measurement": "V",
          "availability": {
            "topic": "de/gudesystems/epc/00:19:32:02:4f:40/device/telemetry",
            "value_template": "{{ 'type' in value_json }}",
            "payload_available": true,
            "payload_not_available": false
          },
          "device": {
            "identifiers": ["pdu_001932024f40"]
          }
        }{%endraw%}
  - delay:
      hours: 0
      minutes: 0
      seconds: 0
      milliseconds: 800
  - alias: "Define Sensor: Line Current measurement"
    action: mqtt.publish
    metadata: {}
    data:
      qos: "0"
      retain: false
      topic: homeassistant/sensor/pdu_001932024f40/line_current/config
      payload: |-
        {%raw%}{
          "name": "PDU Line Current",
          "unique_id": "pdu_001932024f40_line_current",
          "state_topic": "de/gudesystems/epc/00:19:32:02:4f:40/device/telemetry",
          "value_template": "{{ value_json.line_in[0].current }}",
          "state_class": "measurement",
          "device_class": "current",
          "unit_of_measurement": "A",
          "availability": {
            "topic": "de/gudesystems/epc/00:19:32:02:4f:40/device/telemetry",
            "value_template": "{{ 'type' in value_json }}",
            "payload_available": true,
            "payload_not_available": false
          },
          "device": {
            "identifiers": ["pdu_001932024f40"]
          }
        }{%endraw%}
  - delay:
      hours: 0
      minutes: 0
      seconds: 0
      milliseconds: 800
  - alias: "Define Sensor: Line Power measurement"
    action: mqtt.publish
    metadata: {}
    data:
      qos: "0"
      retain: false
      topic: homeassistant/sensor/pdu_001932024f40/line_power/config
      payload: |-
        {%raw%}{
          "name": "PDU Line Power",
          "unique_id": "pdu_001932024f40_line_power",
          "state_topic": "de/gudesystems/epc/00:19:32:02:4f:40/device/telemetry",
          "value_template": "{{ value_json.line_in[0].act_pow }}",
          "state_class": "measurement",
          "device_class": "power",
          "unit_of_measurement": "W",
          "availability": {
            "topic": "de/gudesystems/epc/00:19:32:02:4f:40/device/telemetry",
            "value_template": "{{ 'type' in value_json }}",
            "payload_available": true,
            "payload_not_available": false
          },
          "device": {
            "identifiers": ["pdu_001932024f40"]
          }
        }{%endraw%}
  - delay:
      hours: 0
      minutes: 0
      seconds: 0
      milliseconds: 800
  - alias: >-
      PDU configuration: Set PowerON delay period (for outlets 1 through 8) to
      30 seconds
    repeat:
      for_each: "{{ range(1,9) | list}}"
      sequence:
        - alias: MQTT Publish "port n resettime set 30"
          action: mqtt.publish
          metadata: {}
          data:
            qos: "0"
            topic: de/gudesystems/epc/00:19:32:02:4f:40/cmd/cli
            payload: >-
              {%raw%}port {%endraw%}{{ repeat.item }}{%raw%} resettime set
              30{%endraw%}
        - delay:
            hours: 0
            minutes: 0
            seconds: 0
            milliseconds: 800
    enabled: true
  - alias: "Define Buttons: Power cycle outlet n (1 through 8)"
    repeat:
      for_each: "{{ range(1,9) | list}}"
      sequence:
        - alias: MQTT Publish "port n reset"
          action: mqtt.publish
          metadata: {}
          data:
            qos: "0"
            topic: >-
              homeassistant/button/pdu_001932024f40/outlet_{{ repeat.item
              }}/config
            payload: |-
              {%raw%}{
                "name": "PDU Reset Outlet {%endraw%}{{ repeat.item }}{%raw%}",
                "unique_id": "pdu_001932024f40_reset_outlet_{%endraw%}{{ repeat.item }}{%raw%}",
                "command_topic": "de/gudesystems/epc/00:19:32:02:4f:40/cmd/cli",
                "payload_press": "port {%endraw%}{{ repeat.item }}{%raw%} reset",
                "icon": "mdi:refresh",
                "availability": {
                  "topic": "de/gudesystems/epc/00:19:32:02:4f:40/device/telemetry",
                  "value_template": "{{ 'type' in value_json }}",
                  "payload_available": true,
                  "payload_not_available": false
                },
                "device": {
                  "identifiers": ["pdu_001932024f40"]
                }
              }{%endraw%}
            retain: false
        - delay:
            hours: 0
            minutes: 0
            seconds: 0
            milliseconds: 800
    enabled: true
  - alias: "Define Button: Power cycle ALL outlets"
    action: mqtt.publish
    metadata: {}
    data:
      qos: "0"
      topic: homeassistant/button/pdu_001932024f40/outlet_reset_all/config
      payload: |-
        {%raw%}{
          "name": "PDU Reset ALL Outlets",
          "unique_id": "pdu_001932024f40_reset_all_outlets",
          "command_topic": "de/gudesystems/epc/00:19:32:02:4f:40/cmd/cli",
          "payload_press": "port restart all set 1",
          "icon": "mdi:refresh",
          "availability": {
            "topic": "de/gudesystems/epc/00:19:32:02:4f:40/device/telemetry",
            "value_template": "{{ 'type' in value_json }}",
            "payload_available": true,
            "payload_not_available": false
          },
          "device": {
            "identifiers": ["pdu_001932024f40"]
          }
        }{%endraw%}
      retain: false
alias: MQTT discovery script Gude Systems PDU 8035-3 R2
description: >
  Script to define Gude Systems 8035 R2 series PDU via MQTT discovery.

  For MQTT commands see webpage <https://wiki.gude-systems.com/MQTT_eng> (of
  main interest are the items that start with "port ...").


  The script defines:

  - Line voltage, Line current and Line power sensors,

  - 8 outlet switches, for each outlet power, current and label sensors (the
  latter means labels that are given to an outlet on the PDU, are shown in HA.
  For now, one way sync only),

  - Reset buttons for each outlet to power off and (after a powerON delay of 30
  seconds), power on a given outlet,

  - Reset ALL button to poweroff ALL outlets at once and power on ALL outlets
  with a powerON delay as defined for each outlet in the PDU. Each outlet
  remains off for a period of 30 seconds, 


  All sensor information is extracted from the telemetry data that the PDU
  publishes to MQTT topic de/gudesystems/epc/[mac]/device/telemetry (normally
  each 60 seconds). As a side effect it might take a few seconds (60 seconds at
  most) before sensor information is shown in HA.


  ## How to remove this MQTT device (manual removal via UI only)

  This MQTT discovery script bundle makes about 45 entries. It might happen that
  you are testing the discovery device scripts in this bundle and want to remove
  them all at once. As far as I know, there is no scriptable way to remove a
  MQTT discovery device. You can only do it manually via the steps below:


  1. Go to Settings > Devices & Services.

  2. Find the MQTT integration and click on it.

  3. Locate the PDU 8035-3 R2 device in the list of devices.

  4. Click on the device to open its details page.

  5. Click the three dots (⋮) in the top-right corner and select "Delete
  device".

  6. Confirm the deletion in the dialog that appears.

Gude Systems PDU 8035 series integration via MQTT: Part 4 - The automation script code

Look for the main article at Gude Systems PDU 8035 series integration via MQTT: Part 1 - Introduction

The Automation script code

  Execute PDU 8035-3 R2 MQTT Discovery script when MQTT telemetry data is
  received
description: >-
  Since MQTT discovery data is lost when you reboot Home Assistant, you need to
  execute the PDU MQTT discovery script again at reboot.


  This automation is triggered each time the MQTT broker receives a telemetry
  message from the PDU (meanin the PDU is online and connected to the MQTT
  broker).


  To prevent this script executes the discovery script each time, the variable
  input.boolean.pdu_mqtt_telemetry_received (configured in configuration.yaml)
  is set when the script executed the PDU MQTT discovery script. The initial
  value of input.boolean.pdu_mqtt_telemetry_received is always "false".
triggers:
  - trigger: mqtt
    options:
      topic: de/gudesystems/epc/00:19:32:02:4f:40/device/telemetry
conditions:
  - condition: state
    entity_id: input_boolean.pdu_mqtt_telemetry_received
    state:
      - "off"
actions:
  - action: input_boolean.turn_on
    metadata: {}
    data: {}
    target:
      entity_id: input_boolean.pdu_mqtt_telemetry_received
  - action: script.mqtt_discovery_script_gude_systems_pdu_8035_3_r2_duplicate
    metadata: {}
    data: {}
mode: single

Gude Systems PDU 8035 series integration via MQTT: Part 5 - The Dashboard code

Look for the main article at Gude Systems PDU 8035 series integration via MQTT: Part 1 - Introduction

Due to size restrictions of this forum, I could only upload a trimmed version of the dashboard code: the dashboard code contains all elements except those of outlets 3 through 8. To get those outlets in your dashboard, simply:

  • duplicate outlet 2 in the dashboard editor,
  • switch from visual editor to YAML editor,
  • increase the number of an outlet entry accordingly,
  • save your dashboard.
    Done.
  - title: PDU (trimmed version)
    header:
      card:
        type: markdown
        text_only: true
        content: '# PDU Gude Systems 8035-3 R2'
    sections:
      - type: grid
        cards:
          - type: heading
            heading: Line in
            heading_style: title
            icon: ''
          - type: horizontal-stack
            cards:
              - show_name: false
                show_icon: true
                show_state: true
                type: glance
                entities:
                  - entity: sensor.pdu_8035_3_r2_pdu_line_voltage
              - show_name: false
                show_icon: true
                show_state: true
                type: glance
                entities:
                  - entity: sensor.pdu_8035_3_r2_pdu_line_current
                    show_state: true
              - show_name: false
                show_icon: true
                show_state: true
                type: glance
                entities:
                  - entity: sensor.pdu_8035_3_r2_pdu_line_power
              - type: vertical-stack
                cards:
                  - show_name: true
                    show_icon: true
                    type: button
                    entity: input_boolean.pdu_mqtt_telemetry_received
                    show_state: false
                    name: Telemetry received
                  - type: conditional
                    conditions:
                      - entity: input_boolean.pdu_mqtt_telemetry_received
                        state: 'on'
                    card:
                      type: markdown
                      content: 'yes'
                      title: null
                    else_card:
                      type: markdown
                      content: 'no'
                      title: null
              - show_name: true
                show_icon: true
                type: button
                entity: button.pdu_8035_3_r2_pdu_reset_all_outlets
                name: Power cycle ALL outlets
          - type: heading
            heading: Outlets
            heading_style: title
            icon: ''
          - type: horizontal-stack
            cards:
              - type: markdown
                content: |-
                  Outlet
                  # 1
              - type: conditional
                conditions:
                  - condition: or
                    conditions:
                      - condition: state
                        entity: switch.pdu_8035_3_r2_pdu_outlet_1
                        state: 'on'
                      - condition: state
                        entity: switch.pdu_8035_3_r2_pdu_outlet_1
                        state: 'off'
                card:
                  type: vertical-stack
                  cards:
                    - show_name: false
                      show_icon: true
                      type: button
                      entity: switch.pdu_8035_3_r2_pdu_outlet_1
                      show_state: false
                    - show_name: false
                      show_icon: false
                      show_state: true
                      type: glance
                      entities:
                        - entity: sensor.pdu_8035_3_r2_pdu_outlet_1_label
              - type: conditional
                conditions:
                  - condition: or
                    conditions:
                      - condition: state
                        entity: switch.pdu_8035_3_r2_pdu_outlet_1
                        state: 'on'
                card:
                  type: conditional
                  conditions: []
                  card:
                    type: vertical-stack
                    cards:
                      - show_name: false
                        show_icon: false
                        show_state: true
                        type: glance
                        entities:
                          - entity: sensor.none_pdu_outlet_1_power
                            show_state: true
                            show_last_changed: false
                      - show_name: false
                        show_icon: false
                        show_state: true
                        type: glance
                        entities:
                          - entity: sensor.pdu_8035_3_r2_pdu_outlet_1_current
              - type: conditional
                conditions:
                  - condition: or
                    conditions:
                      - condition: state
                        entity: switch.pdu_8035_3_r2_pdu_outlet_1
                        state: 'off'
                      - condition: state
                        entity: switch.pdu_8035_3_r2_pdu_outlet_1
                        state: unavailable
                      - condition: state
                        entity: switch.pdu_8035_3_r2_pdu_outlet_1
                        state: unknown
                card:
                  type: markdown
                  content: ' '
              - type: conditional
                conditions:
                  - condition: state
                    entity: switch.pdu_8035_3_r2_pdu_outlet_1
                    state: 'on'
                card:
                  show_name: true
                  show_icon: true
                  type: button
                  entity: button.pdu_8035_3_r2_pdu_reset_outlet_1
                  name: Power cycle outlet
              - type: conditional
                conditions:
                  - condition: or
                    conditions:
                      - condition: state
                        entity: switch.pdu_8035_3_r2_pdu_outlet_1
                        state: 'off'
                      - condition: state
                        entity: switch.pdu_8035_3_r2_pdu_outlet_1
                        state: unavailable
                      - condition: state
                        entity: switch.pdu_8035_3_r2_pdu_outlet_1
                        state: unknown
                card:
                  type: markdown
                  content: ' '
          - type: horizontal-stack
            cards:
              - type: markdown
                content: |-
                  Outlet
                  # 2
              - type: conditional
                conditions:
                  - condition: or
                    conditions:
                      - condition: state
                        entity: switch.pdu_8035_3_r2_pdu_outlet_2
                        state: 'on'
                      - condition: state
                        entity: switch.pdu_8035_3_r2_pdu_outlet_2
                        state: 'off'
                card:
                  type: vertical-stack
                  cards:
                    - show_name: false
                      show_icon: true
                      type: button
                      entity: switch.pdu_8035_3_r2_pdu_outlet_2
                      show_state: false
                    - show_name: false
                      show_icon: false
                      show_state: true
                      type: glance
                      entities:
                        - entity: sensor.pdu_8035_3_r2_pdu_outlet_2_label
              - type: conditional
                conditions:
                  - condition: or
                    conditions:
                      - condition: state
                        entity: switch.pdu_8035_3_r2_pdu_outlet_2
                        state: 'on'
                card:
                  type: conditional
                  conditions: []
                  card:
                    type: vertical-stack
                    cards:
                      - show_name: false
                        show_icon: false
                        show_state: true
                        type: glance
                        entities:
                          - entity: sensor.pdu_8035_3_r2_pdu_outlet_2_power
                            show_state: true
                            show_last_changed: false
                      - show_name: false
                        show_icon: false
                        show_state: true
                        type: glance
                        entities:
                          - entity: sensor.pdu_8035_3_r2_pdu_outlet_2_current
              - type: conditional
                conditions:
                  - condition: or
                    conditions:
                      - condition: state
                        entity: switch.pdu_8035_3_r2_pdu_outlet_2
                        state: 'off'
                      - condition: state
                        entity: switch.pdu_8035_3_r2_pdu_outlet_2
                        state: unavailable
                      - condition: state
                        entity: switch.pdu_8035_3_r2_pdu_outlet_2
                        state: unknown
                card:
                  type: markdown
                  content: ' '
              - type: conditional
                conditions:
                  - condition: state
                    entity: switch.pdu_8035_3_r2_pdu_outlet_2
                    state: 'on'
                card:
                  show_name: true
                  show_icon: true
                  type: button
                  entity: button.pdu_8035_3_r2_pdu_reset_outlet_2
                  name: Power cycle outlet
              - type: conditional
                conditions:
                  - condition: or
                    conditions:
                      - condition: state
                        entity: switch.pdu_8035_3_r2_pdu_outlet_2
                        state: 'off'
                      - condition: state
                        entity: switch.pdu_8035_3_r2_pdu_outlet_2
                        state: unavailable
                      - condition: state
                        entity: switch.pdu_8035_3_r2_pdu_outlet_2
                        state: unknown
                card:
                  type: markdown
                  content: ' '
          - type: heading
            heading: ' Mainentance (be sure what you are doing)'
            heading_style: title
            icon: ''
          - type: horizontal-stack
            cards:
              - type: markdown
                content: ' '
              - type: markdown
                content: ' '
              - show_name: true
                show_icon: true
                type: button
                entity: button.pdu_8035_3_r2_pdu_reboot
                name: Restart PDU
              - type: vertical-stack
                cards:
                  - show_name: true
                    show_icon: true
                    type: button
                    entity: input_boolean.pdu_mqtt_telemetry_received
                    show_state: false
                    name: Telemetry received
                  - type: conditional
                    conditions:
                      - entity: input_boolean.pdu_mqtt_telemetry_received
                        state: 'on'
                    card:
                      type: markdown
                      content: 'yes'
                      title: null
                    else_card:
                      type: markdown
                      content: 'no'
                      title: null
        column_span: 1
    type: sections
    max_columns: 1
    cards: []