RESTful or not? Rituals Perfume Genie

So I got a Rituals Perfume Genie (https://www.rituals.com/en-nl/collection-story-perfumegenie.html) which I can control using an API.
Now I want to integrate it into HASS and have been struggling to use a RESTful switch for this purpose.
Is a RESTful switch the way to go?

Some info:

I can get the status of the Genie with the following GET:

https://rituals.sense-company.com/api/account/hubs/<HUB HASH HIDDEN>

This returns the following JSON:

[
	{
		"hub": {
			"hublot": "LOT119-12-A4980-02273",
			"hash": "bcc1f4941651c887b27531ad7b72a4f9d3b979ef8aa706c650608d",
			"status": 1,
			"title": null,
			"current_time": "2020-01-28T09:41",
			"ping_update": "25",
			"attributes": {
				"roomc": "2",
				"speedc": "2",
				"fanc": "0",
				"roomnamec": "Genie",
				"resetc": ""
			},
			"sensors": {
				"wific": {
					"id": 4,
					"sensor_id": 1,
					"title": "Low",
					"description": "This signal is weak",
					"icon": "icon-signal-low.png",
					"image": "",
					"discover_image": "",
					"min_value": "-100.00",
					"max_value": "-70.00",
					"interval": "1",
					"created_at": "2017-03-10 14:31:39",
					"updated_at": "2017-06-21 13:29:05",
					"default": 0
				},
				"battc": {
					"id": 21,
					"sensor_id": 2,
					"title": "Charging",
					"description": "When the device has a power cord connected to it. ",
					"icon": "battery-charge.png",
					"image": "",
					"discover_image": "",
					"min_value": "701",
					"max_value": "1500",
					"interval": "1",
					"created_at": "2017-04-10 15:02:59",
					"updated_at": "2018-10-15 14:29:06",
					"default": 0
				},
				"fillc": {
					"id": 38,
					"sensor_id": 3,
					"title": "90-100%",
					"description": "",
					"icon": "icon-fill.png",
					"image": "",
					"discover_image": "",
					"min_value": "0",
					"max_value": "1000",
					"interval": "",
					"created_at": "2017-10-16 07:50:23",
					"updated_at": "2017-10-16 07:57:37",
					"default": 0
				},
				"rfidc": {
					"id": 54,
					"sensor_id": 4,
					"title": "Private Collection Sweet Jasmine",
					"description": "",
					"icon": "icon-jasmine.png",
					"image": "background-jasmine.png",
					"discover_image": "discover-jasmine.png",
					"min_value": "05377650",
					"max_value": "05377650",
					"interval": "",
					"created_at": "2019-04-04 07:53:32",
					"updated_at": "2019-05-02 14:10:59",
					"default": 0
				},
				"versionc": "1.2.9",
				"ipc": "1578154445",
				"rpsc": {
					"id": 48,
					"sensor_id": 12,
					"title": "Fan on",
					"description": "",
					"icon": "",
					"image": "",
					"discover_image": "",
					"min_value": "5",
					"max_value": "10000",
					"interval": "",
					"created_at": "2018-01-23 12:05:45",
					"updated_at": "2019-08-01 14:54:53",
					"default": 0
				},
				"resetc": "Software/System restart",
				"chipidc": "5377254",
				"errorc": "",
				"onlinec": {
					"id": 31,
					"sensor_id": 16,
					"title": "Online",
					"description": "",
					"icon": "",
					"image": "",
					"discover_image": "",
					"min_value": "1",
					"max_value": "1",
					"interval": "",
					"created_at": "2017-09-07 08:23:30",
					"updated_at": "2017-09-07 08:23:30",
					"default": 0
				}
			},
			"settings": []
		}
	}
]

The status is retrieved from the attribute "fanc": "0",

I can turn on the Genie using the following POST:

https://rituals.sense-company.com/api/hub/update/attr?hub=<HUB HASH HIDDEN>&json={"attr":{"fanc":"1"}}

And off using:

https://rituals.sense-company.com/api/hub/update/attr?hub=<HUB HASH HIDDEN>&json={"attr":{"fanc":"0"}}

Does someone have an idea how to integrate the Genie into HASS? Is a RESTful switch the way to go?

Hi,
How did you get the hash?

  1. Login using POST: https://rituals.sense-company.com/ocapi/login?email=<your email>&password=<your password>

  2. In the response is the “account hash”.Copy and paste in the following GET call to get your hub hash: https://rituals.sense-company.com/api/account/hubs/<your account hash>

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.

Thanks, I got it working your way.

Does this only work for the v2? I have a v1 and get an error:

Whoops, looks like something went wrong.

In Chrome console:
Failed to load resource: the server responded with a status of 405 (Method Not Allowed)

@Rikkie80
Run this command and you will get the info you are looking for.

curl -d "email=<your email>&password=<secret>" https://rituals.sense-company.com/ocapi/login

Then if you take that hash and put it in to this curl

curl -v https://rituals.sense-company.com/api/account/hubs/<hash>

you will get info about your Genie including your Genie’s hash.

i hope i got that right :smiley:

Thanks! With this I’m able to get the hash.
Just from my curiosity… How did you find out that it works this way?

Figured it out that Timmerman talked about curl commande based on some other sites and API’s :slight_smile: It wasnt that easy :smiley:

1 Like

Not working for me, when i switch to ON, the switch goes back to off and nothing happends on the genie. Any ideas? Log says:
Error. Url: https://rituals.sense-company.com/api/hub/update/attr?hub= . Status code 500.

Can’t get it working either,
My configuration.yaml looks like:

binary_sensor:
  - platform: rest
    resource: https://rituals.sense-company.com/api/account/hubs/<key hidden>
    method: GET
    name: Genie Status
    value_template: ‘{{ value_json.0.hub.attributes.fanc == "1" }}’
    
rest_command:
  genie_on:
    method: post
    url: ‘https://rituals.sense-company.com/api/hub/update/attr?hub=<key hidden>&json=={“attr”:{“fanc”:"1"}}’
    content_type: application/json
  genie_off:
    method: post
    url: ‘https://rituals.sense-company.com/api/hub/update/attr?hub=<key hidden>&json=={“attr”:{“fanc”:"0"}}’
    content_type: application/json
    
switch:
  - platform: template
    switches:
      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

When i switch to on it also switches back,
Log says:

Client error ‘https://rituals.sense-company.com/api/hub/update/attr?hub=f&json={“attr”:{“fanc”:“1”}}’

Traceback (most recent call last):
File “/usr/src/homeassistant/homeassistant/components/rest_command/init.py”, line 119, in async_service_handler
timeout=timeout,
File “/usr/local/lib/python3.7/site-packages/aiohttp/client.py”, line 1012, in aenter
self._resp = await self._coro
File “/usr/local/lib/python3.7/site-packages/aiohttp/client.py”, line 473, in _request
ssl=ssl, proxy_headers=proxy_headers, traces=traces)
File “/usr/local/lib/python3.7/site-packages/aiohttp/client_reqrep.py”, line 285, in init
self.update_host(url)
File “/usr/local/lib/python3.7/site-packages/aiohttp/client_reqrep.py”, line 339, in update_host
raise InvalidURL(url)
aiohttp.client_exceptions.InvalidURL: %E2%80%98https://rituals.sense-company.com/api/hub/update/attr?hub=key hidden&json=%7B%E2%80%9Cattr%E2%80%9D:%7B%E2%80%9Cfanc%E2%80%9D:%221%22%7D%7D%E2%80%99

Someone any idea of what is wrong?
Still not getting it to work.

i will go test it. I have also home assistant and a rituals

UPDATE It works! (See screenshot)

image

I can control the rituals with the switch in home assistant!

Hi,

Is it possible to post the code to get this working?
Have been trying for 2 weeks can’t figure it out.

Thx

Hi,

Yes, no problem!
I’ll post it tomorrow.

STEP 1: command in terminal: curl -d “email=&password=” https://rituals.sense-company.com/ocapi/login

STEP 2: you now get a very long code with the above command. copy this code to notepad

STEP 3: go in your browser to: https://rituals.sense-company.com/api/account/hubs/USE HERE THE VERY LONG CODE off step 1/2

STEP 4: now copy the “hash”:" code from step 3 (at the top) to notepad

pay attention: 'and the" characters when entering.
I’ve already modified them here.

binary_sensor:

rest_command:
genie_on:
method: post
url: ‘https://rituals.sense-company.com/api/hub/update/attr?hub=USE THE SHORT “hash”:" CODE out STEP 3/4 HERE&json=={“attr”:{“fanc”:“1”}}’
content_type: application/json
genie_off:
method: post
url: ‘https://rituals.sense-company.com/api/hub/update/attr?hub=USE THE SHORT “hash”:" CODE out STEP 3/4 HERE&json=={“attr”:{“fanc”:“0”}}’
content_type: application/json

switch:

  • platform: template
    switches:
    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

Hello,

do you know if it is possible to get the battery status (full, half full) in a sensor?
I have the rest working nicely.

Hi,
you mean having info about how empty/full is the refill essence?
Or info about the battery of the device itself? Because mine is V2, and it has no battery, it’s always connected.
Regarding info about the essence I think it’s possible because that info is on the rest answer. Once I get all the status from mine I would try to implement a refill warning.

sorry for the confusion.
I mean battery status
I have the V1 version, and it has a battery.

I can read the battery status with URL:

resource: https://rituals.sense-company.com/api/account/hubs/

there he indicates the battery status (Charching, Full, Half Full etc).
I would also like to see this in a sensor, but I don’t know how.
do you know how i can turn this into a sensor?

Thank u,

got it working now, just had to replace al the “” and ‘’ with " and ', the rest of the code i used was correct.