I attempt to read a text sensor I hope to set in in HA, compare it to text and if match, set the ledc output value to drive pwm.
Defining output with platform ledc validates OK, and is not included in the following snippets.
From the first sample in the above picture (on:raw_value) I understood, that I need to use text_sensor: (first line)
For the platform: home assistant, because I wish to read this value from home assistant
From the second sample I figured, that the structure combined should be:
INFO Reading configuration /config/esphome/esphome-web-4da88c.yaml...
ERROR Error while reading config: Invalid YAML syntax:
mapping values are not allowed here
in "/config/esphome/esphome-web-4da88c.yaml", line 55, column 19:
on_raw_value:
^
This is a screenshot showing referred line numbers
Whats the problem? Also for the actions after the comparison, I have no idea about the identation of output.set.level, because the samples are not showing what to do, if comparison is true (or false)…
Yup, that too. The result I ended up with and which is working is:
text_sensor:
- platform: homeassistant
entity_id: input_select.ilto_state
id: "ilto_state"
on_value:
- if:
condition:
text_sensor.state:
id: ilto_state
state: 'state_1'
then:
######################################################
# Must be turned on before setting frequency & level
######################################################
- output.turn_on: ilto_ctrl_pwm
######################################################
# Frequency sets the wave size
######################################################
- output.ledc.set_frequency:
id: ilto_ctrl_pwm
frequency: "1000Hz"
######################################################
# level sets the %age time the PWM is on
######################################################
- output.set_level:
id: ilto_ctrl_pwm
level: "90%"
- if:
condition:
text_sensor.state:
id: ilto_state
state: 'state_2'
then:
######################################################
# Must be turned on before setting frequency & level
######################################################
- output.turn_on: ilto_ctrl_pwm
######################################################
# Frequency sets the wave size
######################################################
- output.ledc.set_frequency:
id: ilto_ctrl_pwm
frequency: "1000Hz"
######################################################
# level sets the %age time the PWM is on
######################################################
- output.set_level:
id: ilto_ctrl_pwm
level: "65%"
- if:
condition:
text_sensor.state:
id: ilto_state
state: 'state_3'
then:
######################################################
# Must be turned on before setting frequency & level
######################################################
- output.turn_on: ilto_ctrl_pwm
######################################################
# Frequency sets the wave size
######################################################
- output.ledc.set_frequency:
id: ilto_ctrl_pwm
frequency: "1000Hz"
######################################################
# level sets the %age time the PWM is on
######################################################
- output.set_level:
id: ilto_ctrl_pwm
level: "40%"
This works OK, and sets the PWM as needed. %-values are based on trial & error.
Also all those elements need to be set: turning output on, setting the frequency and setting the level. At least in this structure.
Maybe there could be use for soime streamlining, but this worked so stopped fiddling about