timmy_pete
01/10/2024, 5:14 AMblaickgaming
01/10/2024, 8:27 AMyaml
rest: !include_dir_merge_list rest/
rest/turing_nodes_info.yaml
yaml
- resource: https://<ip-address>/api/bmc?opt=get&type=nodeinfo
authentication: basic
username: <username>
password: <password>
verify_ssl: false
sensor:
- name: Turing Pi Node 1 Info
value_template: "{{ value_json['response'][0]['result'][0]['node1'] }}"
- name: Turing Pi Node 2 Info
value_template: "{{ value_json['response'][0]['result'][0]['node2'] }}"
- name: Turing Pi Node 3 Info
value_template: "{{ value_json['response'][0]['result'][0]['node3'] }}"
- name: Turing Pi Node 4 Info
value_template: "{{ value_json['response'][0]['result'][0]['node4'] }}"
rest/turing_nodes_power.yaml
yaml
- resource: https://<ip-address>/api/bmc?opt=get&type=power
authentication: basic
username: <username>
password: <password>
verify_ssl: false
sensor:
- name: Turing Pi Node 1 Info
value_template: "{{ value_json['response'][0]['result'][0]['node1'] }}"
- name: Turing Pi Node 2 Info
value_template: "{{ value_json['response'][0]['result'][0]['node2'] }}"
- name: Turing Pi Node 3 Info
value_template: "{{ value_json['response'][0]['result'][0]['node3'] }}"
- name: Turing Pi Node 4 Info
value_template: "{{ value_json['response'][0]['result'][0]['node4'] }}"
As I said before, I have no idea to validate the legitimacy right now, but since you specifically mentioned your unfamiliarity with home assistants JSON-parsing syntax it might give you enough info to implement it.blaickgaming
01/10/2024, 8:27 AMyaml
command_line: !include_dir_merge_list commands/
commands/turing_nodes_power_switch.yaml
yaml
- switch:
name: turing_pi_node_1_power
command_on: "curl --insecure -u '<username>:<password>' -X POST 'https://<ip-address>/api/bmc?opt=power&type=set&node1=1'"
command_off: "curl --insecure -u '<username>:<password>' -X POST 'https://<ip-address>/api/bmc?opt=power&type=set&node1=0'"
command_state: "curl --insecure -u '<username>:<password>' -X GET 'https://<ip-address>/api/bmc?opt=power&type=get'"
value_template: "{{ value_json['response'][0]['result'][0]['node1'] | int == 1 }}"
# Code would become to long for Discord, so just replace 'XXX' with the node index.
- switch:
name: turing_pi_node_XXX_power
command_on: "curl --insecure -u '<username>:<password>' -X POST 'https://<ip-address>/api/bmc?opt=power&type=set&nodeXXX=1'"
command_off: "curl --insecure -u '<username>:<password>' -X POST 'https://<ip-address>/api/bmc?opt=power&type=set&nodeXXX=0'"
command_state: "curl --insecure -u '<username>:<password>' -X GET 'https://<ip-address>/api/bmc?opt=power&type=get'"
value_template: "{{ value_json['response'][0]['result'][0]['nodeXXX'] | int == 1 }}"
timmy_pete
01/10/2024, 12:43 PMtimmy_pete
01/10/2024, 12:50 PMtimmy_pete
01/10/2024, 12:51 PMblaickgaming
01/10/2024, 6:46 PMtimmy_pete
01/16/2024, 1:01 AM- resource: https://xx.xx.xx.xx/api/bmc?opt=get&type=power
authentication: basic
username: user
password: pass
verify_ssl: false
binary_sensor:
- name: tpi-power-node1
value_template: "{{ value_json['response'][0]['result'][0]['node1'] }}"
unique_id: tpi-p1
device_class: connectivity
icon: mdi:power
- name: tpi-power-node2
value_template: "{{ value_json['response'][0]['result'][0]['node2'] }}"
unique_id: tpi-p2
device_class: connectivity
icon: mdi:power
timmy_pete
01/16/2024, 1:03 AM- resource: https://xx.xx.xx.xx/api/bmc?opt=get&type=usb
authentication: basic
username: user
password: pass
verify_ssl: false
sensor:
- name: tpi-usb-state
value_template: "{{ (value_json['response'][0]['result'][0]['mode']) }} mode - {{ (value_json['response'][0]['result'][0]['node']) }} to {{ (value_json['response'][0]['result'][0]['route']) }}"
unique_id: tpi-usb
icon: mdi:usb
timmy_pete
01/16/2024, 1:09 AMtimmy_pete
01/22/2024, 10:21 AMtimmy_pete
01/22/2024, 10:23 AM- resource: https://IP-OR-HOST/api/bmc?opt=get&type=power
authentication: basic
username: user
password: pass
verify_ssl: false
binary_sensor:
- name: tpi-power-node1
value_template: "{{ value_json['response'][0]['result'][0]['node1'] }}"
unique_id: tpi-p1
device_class: connectivity
icon: mdi:power
{.... and so on}
B) Command switch
Note the core issue with @blaickgaming's template above seems to be the use of http POST requests, because the API confusingly uses GETs for set commands.
I've tried dozens of different permutations of the command_state and value_template options, and not been able to find anything that reliably updates the switch state over time. Not including them here means that this switch entity has separate on/off buttons rather than a toggle. This entity is where HA attributes all on off activity for graphing/activity log purposes (rather than the Template switch below, or the binary sensor)
/config/commands/turing_switches.yaml:
- switch:
name: tpi-node1
command_on: "/config/commands/tpi-api.sh power_on node1"
command_off: "/config/commands/tpi-api.sh power_off node1"
{...and so on}
I've also attached my shell script below:
https://cdn.discordapp.com/attachments/1194509611139596318/1198935982075027498/tpi-api.sh?ex=65c0b725&is=65ae4225&hm=eeb8dffdefcb390ad863469f46156a02d92ee9911c62fc0cf46b0d1c575c4d5b&timmy_pete
01/22/2024, 10:23 AMswitch:
platform: template
switches:
tpi_ts_node1:
friendly_name: "Turing Pi Node 1"
value_template: "{{ is_state('binary_sensor.tpi_power_node1', 'on') }}"
turn_on:
- service: switch.turn_on
target:
entity_id: switch.tpi_node1
- service: homeassistant.update_entity
target:
entity_id: binary_sensor.tpi_power_node1
turn_off:
- service: switch.turn_off
target:
entity_id: switch.tpi_node1
- service: homeassistant.update_entity
target:
entity_id: binary_sensor.tpi_power_node1
{... and so on}
timmy_pete
01/22/2024, 10:26 AMtimmy_pete
01/22/2024, 10:31 AMtimmy_pete
01/22/2024, 10:33 AMblaickgaming
01/23/2024, 12:27 AMRogue357
01/23/2024, 2:49 AMtimmy_pete
01/23/2024, 3:00 AMJoesRoom
01/23/2024, 3:13 AMJoesRoom
01/23/2024, 3:14 AM