First, thanks for comming here and read my text
I just came to HASSIO for a week ago, now I try to create a slider that control my rf dimmer and rf button (on/off)
Situation:
Slider at 0, turn off button (rf dimmer will be off)
Slider at 1, rf dimmer at 25% (rf code, broadlink send service)
50%, 75%, 100%
âŠ
Because RF button and RF dimmer are separately, so if I change slider I should check the input number state, if != 0, I should turn on button and than choose suitable dimmer level.
I wrote an automation like this: (automations.yaml)
Error loading /config/configuration.yaml: while scanning for the next token
found character â%â that cannot start any token
in â/config/automations.yamlâ, line 31, column 6
You canât template accross multiple fields. Templates can only be on a single field inside data_template, or other template fields. You are trying to put a list of fields inside your template. This is not possible. Instead, place your actions into 2 separate scripts and fire each script programatically.
Your template was incorrectly grabbing a state object. Youâre missing the state machine object infront of your entity id (states.[domain].[object_id].state). And youâre incorrecty trying to assess the name âvalueâ from it. Iâm not sure where you got this stuff, but you should console the documentation if you donât know the syntax. On top of that, you need to convert the input_numberâs state to the correct type. All states are strings, youâre comparing it to a int, so you need to convert it to an int.
Lastly, your automation has a trigger saying âwhen itâs the state = 1â, but your template checks for when itâs equal to zero. That portion of the service template will never fire because this will only fire when the state equals zero. So that should be removed.
I will use the script as you said above, but when ânight_light_brightness_not_zeroâ, I have 4 level brightness 25%, 50%, 75%, 100%.
Iâll try to do it myself and post here.
Thanks @tom_l and @petro
- alias: Night light rf dimmer on
description: night light sets the brightness based on slider.
trigger:
entity_id: switch.night_light
platform: state
from: 'off'
to: 'on'
condition:
condition: template
value_template: "{{ states('input_number.night_light') | int != 0 }}"
action:
service: script.change_brightness_level_from_on
- alias: Night light on when slider off
description: night light sets the brightness to 100, when slider is zero.
trigger:
entity_id: switch.night_light
platform: state
from: 'off'
to: 'on'
condition:
condition: template
value_template: "{{ states('input_number.night_light') | int == 0 }}"
action:
- service: input_number.set_value
data:
enitity_id: input_number.night_light
value: 4
- service: script.change_brightness_level_from_on
- alias: Night light rf dimmer change
description: Turn off rf dimmer
trigger:
entity_id: input_number.night_light
platform: state
action:
service_template: >
{% if trigger.to_state.state == '0' %}
script.change_brightness_level_to_off
{% else %}
{% if is_state('switch.night_light', 'on') %}
script.change_brightness_level_from_on
{% else %}
script.change_brightness_level_from_off
{% endif %}
{% endif %}
must admit Ive never seen the description field before in automations (or anywhere else in HA Yaml for that matter)
Couldnt find it in the docs either, is this something new and not yet documented maybe?
I added a delay 1s in script on from off, the brightness is now at right level.
Iâll try to fix the issue is when button is off, slider !=0, I draged it to 0, button auto switch on but light is actually off
- alias: Night light on when slider off 2
description: night light sets the brightness to 100, when slider is zero.
trigger:
entity_id: switch.night_light
platform: state
from: 'off'
to: 'on'
condition:
condition: template
value_template: "{{ states('input_number.night_light') | int == 0 }}"
action:
- service: input_number.set_value
data:
enitity_id: input_number.night_light
value: 1
This automation seems not work.
Switch is off, slider at 0.
I change switch to on, slider not set value to 1
Anyone error in this?
P/S: I found it, the last entity is misspell âenitityâ
Slider = 0 means switch off
Slider != 0, switch auto on and choose right brightness level as slider input
Switch off means slider auto at 0.
I use your script and change your automation with my coding way base on your automation
I just donât understand what âtrigger.to_state.stateâ mean ???
This is my automation
- alias: Night light switch on from off
description: Sync (slider 1 when switch on)
trigger:
entity_id: switch.night_light
platform: state
from: 'off'
to: 'on'
condition:
condition: template
value_template: "{{ states('input_number.night_light') | int == 0 }}"
action:
- service: input_number.set_value
data:
entity_id: input_number.night_light
value: 1
- service: script.change_brightness_level_from_on
- alias: Night Light switch on to off
description: Sync (slider 0 when switch off)
trigger:
entity_id: switch.night_light
platform: state
from: 'on'
to: 'off'
action:
- service: input_number.set_value
data:
entity_id: input_number.night_light
value: 0
- alias: Night light brightness level change
description: Night Light change brighness level
trigger:
entity_id: input_number.night_light
platform: state
action:
service_template: >
{% if is_state('switch.night_light', 'off') and states('input_number.night_light') | int != 0 %}
script.change_brightness_level_from_off
{% else %}
{% if states('input_number.night_light') | int == 0 %}
script.change_brightness_level_to_off
{% else %}
script.change_brightness_level_from_on
{% endif %}
{% endif %}