Custom:button-card should trigger rest-command

Hi,

I am a little bit confused how to solve my problem, maybe someone can help me?

The starting point:
I want to define a button, which starts or ends the “one time heat the drinking water up”-function of my heat pump.

The environment:
I have a Remko heat pump which isn’t supported very well in ha. Some guys allready found out how to get and set values via command line and curl and there is a ha-integration to define a few things but I am not able to switch or change settings in ha.

To communicate with the heat pump you have to use the rest-api and the json-format.
This example gets the status of the “one-time heat up”-register (5693):

curl -s http://remko.local/cgi-bin/webapi.cgi --header 'Content-Type: application/json' --data '{"SMT_ID": "0000000000000000","query_list":[5693]}'|jq '.values."5693"'

If the answer is “00” (two zeros) the “one-time heat up” function ist enabled (!), if it is “01” (zero one), the function is disabled.

If I want to change the value (start a one-time heat up) I would send this command:

curl --request POST --url 'http://remko.local/cgi-bin/webapi.cgi' --header 'Content-Type: application/json' --data '{"SMT_ID": "0000000000000000","query_list":[5693],"values": {"5693":"00"}}'

I used the integration as a blue print to define a new sensor and also found a rest-api-example but now I don’t know what to do with it.
The sensor defintion is in a file (I don’t know, if this is a good solution or if there are better solutions but this one works):

class CurrentDHWOperatingStatusSensor(SensorEntity):
    """Representation of a sensor."""

    def __init__(self) -> None:
        """Initialize the sensor."""
        self._state = None

    @ property
    def name(self) -> str:
        """Return the name of the sensor."""
        return 'Remko Aktueller DHW-Aufheiz-Status'

    @ property
    def state(self):
        """Return the state of the sensor."""
        return self._state

    @property
    def icon(self):
        return 'mdi:waves-arrow-right'

    def update(self) -> None:
        """Fetch new state data for the sensor.

        This is the only method that should fetch new data for Home Assistant.
        """

        try:
            operation = RemkoHeatpump().api_request(5693)
            if operation == "00":
                self.hass.data[DOMAIN]["current_dhw_operating_status"] = "On"
            else:
                self.hass.data[DOMAIN]["current_dhw_operating_status"] = "Off"
        except Exception as e:
            _LOGGER.error(
                f"An exception occurred in CurrentDHWOperatingStatusSensor: {e.__str__()}")

        self._state = self.hass.data[DOMAIN]["current_dhw_operating_status"]

The sensor is working as expected and changes the value as soon as I enable the funtion on the heat pump.

Next was the attempt to define a rest-command in the file restcommands.yaml which is imported in the configuration.yaml-file:

remko_set_heating_status:
  url: http://remko.local/cgi-bin/webapi.cgi
  method: POST
  headers:
    accept: "application/json, text/html"
  payload: '{"SMT_ID":"0000000000000000", "query_list":[5693], "values": {"5693": "{{status}}" }}'
  content_type:  'application/json; charset=utf-8'

The goal:
Now I want to define a switch or button-card to toggle the function.
The icon and the color should change with the actual status and there should be a security question “Are you sure?” because I don’t want to start or stop the heat pump unintentional.

I tried something like this but I don’t know how to toogle because it is not a simple boolean/binary value that is flipped. The confusion starts at “tap_action” - the first part is working. How to toggle this? Should I define two rest commands? But even with two rest commands I don’t know what to do.

type: custom:button-card
color_type: icon
icon: mdi:waves
name: One-time heat up off
entity: sensor.remko_aktueller_dhw_aufheiz_status
state:
  - color: green 
    value: 'Off'
  - color: red
    name: One-time heat up ON
    icon: mdi:waves-arrow-right
    value: 'On'
tap_action:
  action: call-service
  confirmation:
    text: Are you sure?
  service: rest_command.remko_set_heating_status
  data:
    state: ???

Ok, I managed to solve my problem.
I defined 2 rest commands and use a “state-switch” - now it works. Maybe I can find an optimized solution with only one command, but not today.