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++;
}