first of all thank for the great community and all the options to get in touch with you guys (Discord, website).
I’m very new to HA and I love it! Previously I was using openHAB but I think HA fits more my needs.
In my HA installation I added a RFXCOM and used the cover.rfxtrx component, which works very well.
But I’m currently not able to get the light.rfxtrx working. Only the “off” switch is working and with this switch (not the “on” button) I can control the light.
Now I have created 4 .sh files with custom commands that can be send to /dev/ttyUSB0 and this works very well.
I also managed to create a switch with shell_command to turn on/off the light.
Question:
How to create a dimmer (or input_number) with step 10 and .sh scripts?
First run of office_light.sh -10%, the second run by -10%… until 0.
First run of office_bright.sh +10%, the second run +10%… until 100.
The shell script looks something link:
echo -e “\x0a\x14\x00\x00…” > /dev/ttyUSB0
Just for clarification: The scripts does not include a value for +/- 10%. It’s just an iterated call of the same command.
Hope you guys could give me a hint and help me getting rid of my headaches.
Let me see if I understand what you’re looking for. You want an input_number that can go from 0 to 100 in steps of 10, and whenever that input_number is changed you want to call one of the shell scripts a number of times depending on whether the change is positive or negative and how big it is (i.e., how many multiples of 10.) Is that right?
Obviously I don’t know the names of your shell commands, etc., and of course I have no way of really testing this, but hopefully this is a start for you.
thank you so much for your answer. You have understood almost everything correctly.
I dont want to call one of the script a number of times. Just once on every state change.
So if I change the input number from 0 to 10 script A should be call. If I change from 10 to 20 the same script should be called. But if I go back from 20 to 10 script B should be called.
But if you change the input_number from 10 to 30… It’s possible for the input_number to be changed by more than one step at a time. That’s why I wrote the code the way I did.
thank you for your response.
I’ve added the input_number section inside of my configuration.yaml, the automation part inside of automations.yaml and the script part inside of scripts.yaml.
Additionally I changed increase_level to increase_level_office and the same for decrease_level.
I get the following error:
2018-07-24 22:39:06 ERROR (MainThread) [homeassistant.config] Invalid config for [script]: [script.adjust_again] is an invalid option for [script]. Check: script->script->adjust_dim_level->sequence->2->script.adjust_again. (See /home/homeassistant/.homeassistant/configuration.yaml, line 78). Please check the docs at https://home-assistant.io/components/script/
2018-07-24 22:39:07 ERROR (MainThread) [homeassistant.setup] Setup failed for script: Invalid config.
2018-07-24 22:39:07 ERROR (MainThread) [homeassistant.config] Invalid config for [input_number]: expected a dictionary for dictionary value @ data['input_number']['decrease_level_office']. Got "echo -ne '\n\x14\x03\x03\x00\x86\x13\x01\x02\x00\x00' > /dev/ttyUSB0"
expected a dictionary for dictionary value @ data['input_number']['increase_level_office']. Got "echo -ne '\n\x14\x03\x03\x00\x86\x13\x01\x01\x00\x00' > /dev/ttyUSB0". (See /home/homeassistant/.homeassistant/configuration.yaml, line 98). Please check the docs at https://home-assistant.io/components/input_number/
2018-07-24 22:39:07 ERROR (MainThread) [homeassistant.setup] Setup failed for input_number: Invalid config.
ERROR (MainThread) [homeassistant.config] Invalid config for [script]: [script.adjust_again] is an invalid option for [script]. Check: script->script->adjust_dim_level->sequence->2->script.adjust_again. (See /home/homeassistant/.homeassistant/configuration.yaml, line 78).
I thought you said you wanted the step to be 10. With a step of 16.667, the other code needs to be adjusted. Probably it’s running in an infinite loop or something.
So, I’m still not sure what’s going on, but here is (in theory) a way to allow any step size, with some potentially helpful improvements:
automations.yaml
# Light office
- alias: Dim light
trigger:
platform: state
entity_id: input_number.office_dimmer
condition:
condition: template
value_template: "{{ trigger.to_state.state != trigger.from_state.state and
trigger.to_state.state is not none and
trigger.from_state.state is not none }}"
action:
service: script.adjust_dim_level
data_template:
command: >
{% if trigger.to_state.state|float > trigger.from_state.state|float %}
shell_command.increase_level_office
{% else %}
shell_command.decrease_level_office
{% endif %}
steps: >
{{ ((trigger.to_state.state|float - trigger.from_state.state|float)|abs
/ state_attr('input_number.office_dimmer', 'step'))|round }}
Now, I still can’t see why you were sometimes getting the 'steps' is undefined error, but regarding the “already running”, maybe that can be addressed like this:
Well I’m stumped. I have no idea why that isn’t working or why you’re getting the error about steps being undefined.
@petro, if you have some time, would you mind looking this over? The problem is probably staring us in the face, but for the life of me, I can’t see it.