RESTful or not? Rituals Perfume Genie

This is what I’ve done (I’m not sure if it’s possible to use a RESTFul switch in this case):

  • Create rest binary sensor:

platform: rest
resource: https://rituals.sense-company.com/api/account/hubs/<HASH_RITUALS>
method: GET
name: Genie Status
value_template: ‘{{ value_json.0.hub.attributes.fanc == “1” }}’

  • Create two rest commands:

rest_command:
genie_on:
method: post
url: ‘https://rituals.sense-company.com/api/hub/update/attr?hub=<HASH_HUB>&json={“attr”:{“fanc”:“1”}}’
content_type: application/json
genie_off:
method: post
url: ‘https://rituals.sense-company.com/api/hub/update/attr?hub=<HASH_HUB>&json={“attr”:{“fanc”:“0”}}’
content_type: application/json

  • Then create a template switch:
 genie:
    friendly_name: "Genie"
    value_template: "{{ is_state('binary_sensor.genie_status', 'on') }}"
    turn_on:
      service: rest_command.genie_on
    turn_off:
      service: rest_command.genie_off

Best regards.