I have a created a sensor in configuration.yaml that passed my information to TP Link to get my token to interact with devices. The token is stored as "TP Link Token".
I understand I need to use some variation of {{ states(sensor.tp_link_token) }} to pass token to the CURL command. I am messing something up with the formatting of the command. Below is what I have, and I need to replace TOKEN with the sensor value. When I manually set TOKEN to the value it works perfectly in HA, but after trying about a dozen times to get the syntax right, I haven't been able to pull the value in from sensor. The examples I found wrap it in quotes, but that did not seem to work for me, as it would pass literally "{{ states(sensor.tp_link_token) }}" or "{{ states['sensor.tp_link_token'] }}" as the token rather than the value.
command_line:
- switch:
name: Remote Switch
command_on: curl --request POST https://use1-wap.tplinkcloud.com/?token=TOKEN --data '{"method":"passthrough","params":{"deviceId":"DEVICE_ID","requestData":"{\"system\":{\"set_relay_state\":{\"state\":1}}}"}}' --header "Content-Type:application/json"
command_off: curl --request POST https://use1-wap.tplinkcloud.com/?token=TOKEN --data '{"method":"passthrough","params":{"deviceId":"DEVICE_ID","requestData":"{\"system\":{\"set_relay_state\":{\"state\":0}}}"}}' --header "Content-Type:application/json"
command_state: curl -s --request POST https://wap.tplinkcloud.com/?token=TOKEN --data '{"method":"passthrough","params":{"deviceId":"DEVICE_ID","requestData":"{\"system\":{\"get_sysinfo\":null},\"emeter\":{\"get_realtime\":null}}"}}' --header "Content-Type:application/json"
value_template: "{{ (value_json.result.responseData.split('relay_state\":')[1][0]) == '1' }}"