Hello All,
I have two separate standard buttons that execute a single command each to set PUSH alerts ON and OFF for a Reolink NVR:
rest_command:
reolink_push_on:
url: http://192.168.1.55/api.cgi?cmd=SetPushV20&user=[USER]&password=[PASSWORD]
payload: '[{"cmd":"SetPushV20","param":{"Push":{"enable":1}}}]'
reolink_push_off:
url: http://192.168.1.55/api.cgi?cmd=SetPushV20&user=[USER]&password=[PASSWORD]
payload: '[{"cmd":"SetPushV20","param":{"Push":{"enable":0}}}]'
Currently, every command (reolink_push_on
and reolink_push_off
) are included into two different buttons, and they work fine. The PUSH stated is displayed in a separate sensor.reolink_push
entity entry in lovelace:
sensor:
- platform: rest
resource: http://192.168.1.55/api.cgi?cmd=GetPushV20&user=[USER]&password=[PASSWORD]
name: Reolink Push
value_template: '{{ value_json[0].value.Push.enable | regex_replace(find="0", replace="Deshabilitado", ignorecase=False) | regex_replace(find="1", replace="Habilitado", ignorecase=False) }}'
method: GET
In order to optimize my lovelace dashboard look&feel, what I would like to do is to have one single HACS custom button card with a toggle switch, for it to enable/disable PUSH alerts on a Reolink NVR and display its state with a color or icon change. So far, I have coded the following for the single button:
type: custom:button-card
entity: sensor.reolink_push
icon: mdi:cellphone-message
show_name: false
color: rgb(0, 122, 193)
state:
- value: Enabled
color: rgb(248, 216, 89)
tap_action:
[???]
I have been able to do other “standard” custom buttons with no issues, but I could code them with standard toggle switches or automation toggles. However, I am not sure how to complete the code for these specific two REST commands above in the first piece of code for the button to be handled as a toggle switch. I have been reading the documentation related to Command Line Switches or RESTful ones, but I am not sure how to do it for this specific scenario. Any help on how to convert the two rest_commands into a switch or other alternative, please?