Snmp switch for pdu with buildup payload with a template

I got a PDU that I want to build up the payload of the SNMP set command with a template. See the code of current config that is not working that I want to get working. I will replace the 0 and 1 with the same if statement code if I get this to work. thanks for any suggestion

- platform: snmp
  baseoid: 1.3.6.1.4.1.17420.1.2.9.1.13.0
  command_payload_off: "{% if is_state('input_boolean.pdu_1_outlet','on') -%}1{%- else -%}0{%- endif %},{% if is_state('input_boolean.pdu_2_outlet','on') -%}1{%- else -%}0{%- endif %},{% if is_state('input_boolean.pdu_3_outlet','on') -%}1{%- else -%}0{%- endif %},0,0,0,0,0"
  command_payload_on: "{% if is_state('input_boolean.pdu_1_outlet','on') -%}1{%- else -%}0{%- endif %},{% if is_state('input_boolean.pdu_2_outlet','on') -%}1{%- else -%}0{%- endif %},{% if is_state('input_boolean.pdu_3_outlet','on') -%}1{%- else -%}0{%- endif %},1,1,1,1,1"
  community: xxxxx
  version: "1"
  host: 192.168.xx.xx
  name: pdu set outlet
  vartype: OctetString

I have a PDU from the same vendor. https://www.digipower.com.tw/single-post/2019/08/02/snmp-mib-for-pdu-outelet-onoff was helpful - you can set them up as individual switches as:

OutletA on 1,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5
OutletA off 0,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5
OutletB on 5,1,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5
OutletB off 5,0,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5

edit: I’ve just run into SNMP Switches that use string lack relaxed matching capability · Issue #42106 · home-assistant/core · GitHub . Damn.

logger:
  filters:
    homeassistant.components.snmp.switch:
      - "Invalid payload .*,.,.,.* received for entity .* state is unknown"

sensor:
  - platform: snmp
    baseoid: 1.3.6.1.4.1.17420.1.2.9.1.13.0
    host: digipower.lan
    name: Digipower Switch State String
    community: !secret digipower_snmp_community
    unique_id: digipower_switch_state_string

switch:
  - platform: snmp
    baseoid: 1.3.6.1.4.1.17420.1.2.9.1.13.0
    command_payload_off: "0,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5"
    command_payload_on: "1,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5"
    community: !secret digipower_snmp_community
    host: digipower.lan
    name: Digipower SNMPSWITCH A
    vartype: OctetString
    version: "1"
  - platform: snmp
    baseoid: 1.3.6.1.4.1.17420.1.2.9.1.13.0
    command_payload_off: "5,0,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5"
    command_payload_on: "5,1,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5"
    community: !secret digipower_snmp_community
    host: digipower.lan
    name: Digipower SNMPSWITCH B
    vartype: OctetString
    version: "1"

- platform: template
  switches:
    # generate_snmp_templateswitches.php
    digipower_outlet_a:
      friendly_name: "Digipower Outlet A"
      unique_id: "digipower_outlet_a"
      icon_template: "mdi:power-socket"
      value_template: "{{ states.sensor.digipower_switch_state_string.state.split(',')[0]|int > 0 }}"
      turn_on:
        action: switch.turn_on
        target:
          entity_id: switch.digipower_snmpswitch_a
      turn_off:
        action: switch.turn_off
        target:
          entity_id: switch.digipower_snmpswitch_a
    digipower_outlet_b:
      friendly_name: "Digipower Outlet B"
      unique_id: "digipower_outlet_b"
      icon_template: "mdi:power-socket"
      value_template: "{{ states.sensor.digipower_switch_state_string.state.split(',')[1]|int > 0 }}"
      turn_on:
        action: switch.turn_on
        target:
          entity_id: switch.digipower_snmpswitch_b
      turn_off:
        action: switch.turn_off
        target:
          entity_id: switch.digipower_snmpswitch_b
<?php

$switches = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x'];

$i=0;
foreach ($switches as $switch)
{
$upper=strtoupper($switch);

$payloadon = substr(str_repeat("5,",$i)."1,".str_repeat("5,",23-$i)."5",0,47);
$payloadoff = substr(str_repeat("5,",$i)."0,".str_repeat("5,",23-$i)."5",0,47);
// 5,0,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5
echo <<<END
  - platform: snmp
    baseoid: 1.3.6.1.4.1.17420.1.2.9.1.13.0
    command_payload_off: "$payloadoff"
    command_payload_on: "$payloadon"
    community: !secret digipower_snmp_community
    host: digipower.lan
    name: Digipower SNMPSWITCH $upper
    vartype: OctetString
    version: '1'

END;
$i++;
}
<?php

$switches = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x'];

$i=0;
foreach ($switches as $switch)
{
$upper=strtoupper($switch);

echo <<<END
      digipower_outlet_$switch:
        friendly_name: "Digipower Outlet $upper"
        unique_id: "digipower_outlet_$switch"
        value_template: "{{ states.sensor.digipower_switch_state_string.state.split(',')[$i]|int > 0 }}"
        turn_on:
            action: switch.turn_on
            target:
                entity_id: switch.digipower_snmpswitch_$switch
        turn_off:
            action: switch.turn_off
            target:
                entity_id: switch.digipower_snmpswitch_$switch

END;
$i++;
}