sensor:
  - platform: command_line
    name: Sonos Sleep Timer remains
    command: >
      curl -X POST http://10.0.3.33:1400/MediaRenderer/AVTransport/Control \
      -H 'Content-Type: text/xml; charset=utf-8' \
      -H 'SOAPAction: "urn:schemas-upnp-org:service:AVTransport:1#GetRemainingSleepTimerDuration"' \
      --data '<?xml version="1.0"?>
              <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
                <s:Body>
                  <u:GetRemainingSleepTimerDuration xmlns:u="urn:schemas-upnp-org:service:AVTransport:1">
                    <InstanceID>0</InstanceID>
                  </u:GetRemainingSleepTimerDuration>
                </s:Body>
              </s:Envelope>'
    value_template: >
      {% set result = value | regex_findall('<RemainingSleepTimerDuration>([\d:]+)</RemainingSleepTimerDuration>') %}
      {% if result %}
        {{ result[0] }}
      {% else %}
        '00:00:00'
      {% endif %}
    scan_interval: 60
