You could rename the ID in the REST API to cube_rotation. That way you separate the two sensors.
PUT http://ip-address:40850/api/restapi-key/sensors/46 and in the body:
{
"name": "living_room_cube_rotation"
}
That would make these two sensors:
"42": {
"config": {
"battery": 88,
"on": true,
"reachable": true,
"temperature": 2200
},
"ep": 2,
"etag": "bac52d206b56327d29293ebeb8f38fad",
"manufacturername": "LUMI",
"mode": 1,
"modelid": "lumi.sensor_cube",
"name": "living_room_cube",
"state": {
"buttonevent": 5000,
"gesture": 5,
"lastupdated": "2019-09-15T17:59:47"
},
"swversion": "20160407",
"type": "ZHASwitch",
"uniqueid": "00:15:8d:00:01:04:1d:e0-02-0012"
},
"46": {
"config": {
"battery": 88,
"on": true,
"reachable": true,
"temperature": 2200
},
"ep": 3,
"etag": "df9d650b630492cb4b077aaa6a7c6ca1",
"manufacturername": "LUMI",
"mode": 1,
"modelid": "lumi.sensor_cube",
"name": "living_room_cube_rotation",
"state": {
"buttonevent": 1416,
"gesture": 7,
"lastupdated": "2019-09-15T17:59:57"
},
"type": "ZHASwitch",
"uniqueid": "00:15:8d:00:01:04:1d:e0-03-000c"
}
And the volume automations:
---
# Turn the volume up in the living room with the Xiaomi Cube
#
alias: living_room_cube_turn_volume_up
initial_state: 'on'
trigger:
platform: event
event_type: deconz_event
event_data:
id: living_room_cube_rotation
condition:
condition: template
value_template: >
{{ trigger.event.data.event | int > 0 }}
action:
service: media_player.volume_set
data_template:
entity_id: media_player.woonkamer
volume_level: >
{% set state = states.media_player.woonkamer.attributes.volume_level + 0.02 -%}{{ state }}
---
# Turn the volume down in the living room with the Xiaomi Cube
#
alias: living_room_cube_turn_volume_down
initial_state: 'on'
trigger:
platform: event
event_type: deconz_event
event_data:
id: living_room_cube_rotation
condition:
condition: template
value_template: >
{{ trigger.event.data.event | int < 0 }}
action:
service: media_player.volume_set
data_template:
entity_id: media_player.woonkamer
volume_level: >
{% set state = states.media_player.woonkamer.attributes.volume_level - 0.02 %}
{% if state <= 0 %}
{% set state = 0 %}{{ state }}
{% else %}
{{ state }}
{% endif %}