Hi m8. Could i ask you to share the code for the mode-control for the cube as well?
Do you have any kind of public library? Your solutions looks fantastic, so i would love to be inspired - and copy/paste some of the solutions too
Hi m8. Could i ask you to share the code for the mode-control for the cube as well?
Do you have any kind of public library? Your solutions looks fantastic, so i would love to be inspired - and copy/paste some of the solutions too
This from my input_select.yaml
cubemode:
name: Cube Mode
options:
- Music
- Lights
- None
initial: Lights
icon: mdi:cube-outline
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:
light['3']spot
instead of light.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’?