Thanks! And “mode-change”?
(Do you have any kind of public library? )
I change my mode by simply throwing it in the air
Automation:
- alias: Xiaomi Cube - Toggle Cube Mode [Free Fall]
trigger:
platform: event
event_type: cube_action
event_data:
entity_id: binary_sensor.cube_158d000101bded
action_type: free_fall
action:
service: input_select.select_option
data_template:
entity_id: input_select.cube_mode
option: >
{% if states.input_select.cube_mode.state == "Radio" %} Light
{% elif states.input_select.cube_mode.state == "Light" %} Radio
{% endif %}
Thanks Bob! Btw. Are you from the China-area, or have i missed out an additional featur, forcing the Xiaomi Gateway, to play other things than China-kind of radio? (Cause i thought that web-radio from China ONLY was the only option, and for sure other basic feature, including the alarm and so on…)
@exetico no I’m from the Netherlands. I don’t use my gateway as a speaker. I use my Chromecast radio for that and use the cube (among other triggers) to start the radio script.
Take a look at this topic if you’re interested: Chromecast radio
Thanks again…
And the last one… I’m trying to use your sample for how to use the rotations to control the light, but i’m facing a error everytime:
2018-02-20 20:39:59 ERROR (MainThread) [homeassistant.config] Invalid config for [automation]: invalid template (TemplateSyntaxError: expected token 'end of print statement', got 'spot') for dictionary value @ data['action'][0]['data_template']['brightness']. Got None. (See ?, line ?). Please check the docs at https://home-assistant.io/components/automation/
Here is my automation (All the other ones for 90 and 180 deg. works just fine):
- alias: Cube event Brightness [Rotate]
initial_state: 'on'
trigger:
- platform: event
event_type: cube_action
event_data:
entity_id: binary_sensor.cube_158d000103a06f
action_type: rotate
#condition:
# - condition: state
# entity_id: input_select.cubemode
# state: 'Lights'
action:
- service: light.turn_on
data_template:
entity_id: light.3spot
brightness: >-
{%if trigger.event.data.action_value | float > 0 %}
{{ states.light.3spot.attributes.brightness | int + 50 }}
{% else %}
{{ states.light.3spot.attributes.brightness | int - 50 }}
{% endif %}
Are you sure your entity_id is right?
Perhaps Hass doesn’t like the numeric part. You can try three things:
- Try it when the light is allready on (and there is a brightness state to work with).
- remove the “3” (so change the name of your entity).
- try
light['3']spot
instead oflight.3spot
Yes, as i can see :)?
And it works fine like this:
- alias: Cube event flip90
trigger:
platform: event
event_type: cube_action
event_data:
entity_id: binary_sensor.cube_158d000103a06f
action_type: flip90
action:
- service: light.turn_on
entity_id: light.3spot
data:
brightness: 200
When in a template you have to do it like Bob’s 3rd option if you have numbers in the name.
And no I don’t have an online repo or github.
I not tried with:
- alias: Cube event Brightness [Rotate]
initial_state: 'on'
trigger:
- platform: event
event_type: cube_action
event_data:
entity_id: binary_sensor.cube_158d000103a06f
action_type: rotate
#condition:
# - condition: state
# entity_id: input_select.cubemode
# state: 'Lights'
action:
- service: light.turn_on
data_template:
entity_id: light.3spot
brightness: >-
{%if trigger.event.data.action_value | float > 0 %}
{{ states.light['3']spot.attributes.brightness | int + 50 }}
{% else %}
{{ states.light['3']spot.attributes.brightness | int - 50 }}
{% endif %}
But the error keeps going:
2018-02-20 21:04:43 ERROR (MainThread) [homeassistant.config] Invalid config for [automation]: invalid template (TemplateSyntaxError: expected token 'end of print statement', got 'spot') for dictionary value @ data['action'][0]['data_template']['brightness']. Got None. (See ?, line ?). Please check the docs at https://home-assistant.io/components/automation/
The config is confirmed OK, if i remove that part of the code, so something isn’t correct, but i’m not sure, that it is…
The automation is in a large package, with multiple other automations. Could that be the issue?
Edit: Nope… Same issue in a seperated file.
Like this …
{{ states.light[‘3spot’].attributes.brightness}}
What a miss… Sorry! And i also managed to put in
` instead of ’ after your post. What a day - i used more than two hours trying to figure out what i missed. And it’s not the first time, where i have forgotten the important stuff about [’ '] if numbers is present in the entity_id.
Again, Thanks both of you, guys!
No worries I make sure I don’t have any numbers in my entity id’s because I always forget this
Guess that how i would build it I’m just preparing everything before the permanent bulb-solutions is mounted.
And… Just for all of you, trying to copy/paste my code with errors - Here is the CORRECT ONE:
- alias: Cube event Brightness [Rotate]
initial_state: 'on'
trigger:
- platform: event
event_type: cube_action
event_data:
entity_id: binary_sensor.cube_158d000103a06f
action_type: rotate
#condition:
# - condition: state
# entity_id: input_select.cubemode
# state: 'Lights'
action:
- service: light.turn_on
data_template:
entity_id: light.3spot
brightness: >-
{%if trigger.event.data.action_value | float > 0 %}
{{ states.light['3spot'].attributes.brightness | int + 50 }}
{% else %}
{{ states.light['3spot'].attributes.brightness | int - 50 }}
{% endif %}
Mode-condition can be enabled by removing the #, and @Bob_NL provided the code for the Mode-change:
And the input in input_select.yaml:
@keithh666 - My Xiaomi Gateway yeels at me then i throw it, and the last status goes to “iam”. Is it just something i messed up in the Xiaomi app?
Update: Changed from cube_mode
to cubemode
.
I think that might be the alert mode, just try dropping it into your hand, you can use any of flip90, flip180, move, tap_twice, shake_air, swing, alert, free_fall and rotate - rotate is the only one with a -/+ve number associated with it so is the only one for brightness/vol
Yep! I already used on of the others
Make sense, about the alert mode. Thanks!
Be aware of the fact that I use input_boolean.cube_mode in my setup and @keithh666 uses input_boolean.cubemode (without the underscore).
You have to make sure there are the same in your config.
Yes! I spotted that yesterday, thanks! Just made a few edits in the post - I’m on the mobile… Hopefully all is corrected
Building on the great collective work of all the previous posts, here’s my variation on using cube rotate to control volume.
I don’t have a specific media player, so I use it to control the volume on the Ubuntu machine where I play music and videos.
Volume adjust is proportional to rotation, I wanted to test that first and I find that it works fairly well.
This is the automation that controls an input number and then sends the command to the Ubuntu machine.
- id: cuberotate
alias: Cube Rotate Volume
trigger:
platform: event
event_type: cube_action
event_data:
entity_id: binary_sensor.cube_158d000117f484
action_type: rotate
action:
- service: input_number.set_value
data_template:
entity_id: input_number.speakers_volume
value: '{{ (states.input_number.speakers_volume.state | int) + (trigger.event.data.action_value | int) }}'
- service: shell_command.volume_control
I used an input number in between because I couldn’t find a way for the shell command to directly take the cube rotation action value. Is it possible to read the rotation value any way other than as a trigger.event?
input_number:
speakers_volume:
name: Speakers Volume
initial: 40
min: 0
max: 120
step: 1
shell_command:
volume_control: 'ssh [email protected] pactl set-sink-volume 0 {{ states.input_number.speakers_volume.state | int }}%'
Also, Has anyone figured out how to do ‘swing’ action, and how to consistently do ‘alert’?
Inspired by others, sharing what I’ve ended up with so far:
- four modes that can be operated from two cubes: Volume mode, Light brightness mode, light warmth mode, temperature mode.
- Drop a cube and it says it’s current mode
- shake a cube and it moves to the next mode.
- I think I might make flip 90 toggle the current entity on/off too.
- I haven’t implemented temperature mode yet, which will control my dumb aircon via my xiaomi IR remote
It works, but I don’t feel like having the separate automations/conditions is the most elegant implementation. I tried to do clever stuff with passing variables between automations and scripts, and various other approaches, but I couldn’t get them working.
In my config file:
input_select:
cube_mode:
name: 'Cube Mode'
options:
- volume
- lighting levels
- lighting warmth
- temperature
In my automatons file
- id: '112'
alias: Change Cube Mode
trigger:
- platform: event
event_type: cube_action
event_data:
entity_id: binary_sensor.cube_158d0001038d22
action_type: shake_air
- platform: event
event_type: cube_action
event_data:
entity_id: binary_sensor.cube_158d00010fd2a6
action_type: shake_air
action:
- service: input_select.select_next
entity_id: input_select.cube_mode
- service: media_player.volume_set
data:
entity_id: media_player.living_room_google
volume_level: '0.3'
- service: tts.google_say
data_template:
entity_id: media_player.living_room_google
message: '{{states.input_select.cube_mode.state}}'
- id: '121'
alias: Say current mode
trigger:
- platform: event
event_type: cube_action
event_data:
entity_id: binary_sensor.cube_158d0001038d22
action_type: free_fall
- platform: event
event_type: cube_action
event_data:
entity_id: binary_sensor.cube_158d00010fd2a6
action_type: free_fall
action:
- service: media_player.volume_set
data:
entity_id: media_player.living_room_google
volume_level: '0.3'
- service: tts.google_say
data_template:
entity_id: media_player.living_room_google
message: '{{states.input_select.cube_mode.state}}'
- id: '120'
alias: "Adjust Cube Lighting Levels"
initial_state: 'on'
trigger:
- platform: event
event_type: cube_action
event_data:
entity_id: binary_sensor.cube_158d00010fd2a6
action_type: rotate
- platform: event
event_type: cube_action
event_data:
entity_id: binary_sensor.cube_158d0001038d22
action_type: rotate
action:
- condition: state
entity_id: input_select.cube_mode
state: 'lighting levels'
- service: light.turn_on
data_template:
entity_id: light.living_area_lights
brightness: >
{%if trigger.event.data.action_value | float > 0 %}
{{states.light.living_area_lights.attributes.brightness| int + 50}}
{% else %}
{{states.light.living_area_lights.attributes.brightness| int - 50}}
{%endif %}
- id: '121'
alias: "Adjust Cube Volume Levels"
initial_state: 'on'
trigger:
- platform: event
event_type: cube_action
event_data:
entity_id: binary_sensor.cube_158d00010fd2a6
action_type: rotate
- platform: event
event_type: cube_action
event_data:
entity_id: binary_sensor.cube_158d0001038d22
action_type: rotate
action:
- condition: state
entity_id: input_select.cube_mode
state: 'volume'
- service: media_player.volume_set
data_template:
entity_id: media_player.the_mothership_3
volume_level: >
{%if trigger.event.data.action_value | float > 0 %}
{{states.media_player.the_mothership_3.attributes.volume_level| float + 0.02}}
{% else %}
{{states.media_player.the_mothership_3.attributes.volume_level| float - 0.02}}
{%endif %}
- id: '122'
alias: "Adjust Cube Lighting Warmth"
initial_state: 'on'
trigger:
- platform: event
event_type: cube_action
event_data:
entity_id: binary_sensor.cube_158d00010fd2a6
action_type: rotate
- platform: event
event_type: cube_action
event_data:
entity_id: binary_sensor.cube_158d0001038d22
action_type: rotate
action:
- condition: state
entity_id: input_select.cube_mode
state: 'lighting warmth'
- service: light.turn_on
data_template:
entity_id: light.living_area_lights
color_temp: >
{%if trigger.event.data.action_value | float > 0 %}
{{states.light.living_area_lights.attributes.color_temp| int + 100}}
{% else %}
{{states.light.living_area_lights.attributes.color_temp| int - 100}}
{%endif %}
This is working pretty well, but I got a bit sick of not being able to quickly tell what mode the cube was in (volume, lighting etc) so I changed the change mode action to ‘flip90’ and put some visual indicators on it (the modes are on the four faces that circumnavigate (?) the cube, and the two remaining faces have indicators for which direction to use to change mode (you can’t reverse direction, you have to "go all the way around).
I just used black duck tape and a whiteout pen for the prototype, but I’ll probably have to replace it with something more abrasive resistant.