How to wrap a sensor and button in a switch

My main dashboard contains a number of cards that use switches. I am adding another card that I would like to appear and behave the same, but which uses an integration that only presents a sensor and a button, not a switch. Is it possible for me to create a switch somehow, that has it’s state set to the state of the sensor, and that when toggled actually presses (toggles) the underlying button? Any help much appreciated.

Yes. Create a template switch which has its state on or off based on the value of the sensor.

Ie

switch:
  - platform: template
    switches:
      Switch_Name:
        value_template: "{{ is_state('sensor.yoursensor', 'on') }}"
        turn_on:
          service: button.press
          target:
            entity_id: button.yourbutton
        turn_off:
          service: button.press
          target:
            entity_id: button.yourbutton

hello
sorry for reopen that old topic, but i seem to be to stupid to reproduce ur code…

        it_mute:
          friendly_name: "Mute pc"
          value_template: "{{ is_state('sensor.pc_audio_default_device_muted', 'on') }}"
          turn_on:
            action: button.press
            target:
              entity_id: button.pc_mediamute
          turn_off:
            action: button.press
            target:
              entity_id: button.pc_mediamute

the sensor has only the value of true (when muted) and false (when sound is on). I have this Button that only can toggle - so i tought making an switch out of it would solve all my problems - sadly that switch resulting out of this code above doesnt help at all - it dont controll if the computer is alrleady muted and toggles anyway
sorry i tried to read into the docu of templates - but it seems i dont get how they really work
any hint would be helpfull

stupid me… i just had to change the value of the sensor to “True” as this is what the Sensor offers… anyhow thanks and good luck everybody else who is reading this