Error when creating toggle automation

Im trying to control my roller curtain. I have it set up so that if it receives a 1 or 0, it activates the dc motor in one direction or another. If I add value of 1 it fails but if I add value of 0 it works:



But my toggle doesnt show up on my dashboard

So I went to hassio and Ive got this so far:

# Example configuration.yaml entry
input_boolean:
  notify_home:
    name: Publish MQTT msg
    icon: mdi:car

  power_kompressor:
    name: Kompressor
    icon: mdi:car

  power_solenoid:
    name: Solenoid
    icon: mdi:car

  power_curtain:
    name: Curtains
    icon: mdi:home

# MQTT Switches RPi2 - RPi3
switch:
  - platform: mqtt
    name: kompressor
    command_topic: "test_channel"
    payload_on: "komp-on"
    payload_off: "komp-off"
  - platform: mqtt
    name: solenoid
    command_topic: "test_channel"
    payload_on: "sole-on"
    payload_off: "sole-off"
  - platform: mqtt
    name: curtains
    command_topic: "curtainStatus"
    payload_on: "1"
    payload_off: "0"

And this is my automations:

- id: '1540843414270'
  alias: MQTT T1R1 ON
  trigger:
  - entity_id: input_boolean.notify_home
    from: 'off'
    platform: state
    to: 'on'
  condition: []
  action:
  - data:
      payload_template: '01'
      topic: test_channel
    service: mqtt.publish
- id: '1541035109238'
  alias: MQTT T1R1 OFF
  trigger:
  - entity_id: input_boolean.notify_home
    from: 'on'
    platform: state
    to: 'off'
  condition: []
  action:
  - data:
      payload_template: '02'
      topic: test_channel
    service: mqtt.publish
- id: '1541282916869'
  alias: Kompressor ON
  trigger:
  - entity_id: input_boolean.power_kompressor
    platform: state
    to: 'on'
  condition: []
  action:
  - data:
      payload_template: '{{ states.input_boolean.power_kompresor.state }}'
      topic: test_channel
    service: mqtt.publish
- id: '1541283025484'
  alias: Kompressor OFF
  trigger:
  - entity_id: input_boolean.power_kompressor
    platform: state
    to: 'off'
  condition: []
  action:
  - data:
      payload_template: '{{ states.input_boolean.power_kompresor.state }}'
      topic: test_channel
    service: mqtt.publish
- id: '1541283060236'
  alias: Solenoid ON
  trigger:
  - entity_id: input_boolean.power_solenoid
    platform: state
    to: 'on'
  condition: []
  action:
  - data:
      payload_template: '{{ states.input_boolean.power_solenoid.state }}'
      topic: test_channel
    service: mqtt.publish
- id: '1541283088175'
  alias: Solenoid OFF
  trigger:
  - entity_id: input_boolean.power_solenoid
    platform: state
    to: 'off'
  condition: []
  action:
  - data:
      payload_template: '{{ states.input_boolean.power_solenoid.state }}'
      topic: test_channel
    service: mqtt.publish
- id: '1585523916793'
  alias: Enrolar Cortinas
  description: ''
  trigger:
  - payload: '0'
    platform: state
    topic: curtainStatus
  condition: []
  action:
  - entity_id: input_boolean.rollup_curtain
    service: mqtt.publish
- id: '1585524161515'
  alias: Desrolar Cortinas
  description: ''
  trigger:
  - payload: '1'
    platform: state
    topic: curtainStatus
  condition: []
  action:
  - data: {}
    entity_id: input_boolean.rollup_curtain
    service: mqtt.publish

You need data_template instead of data any time you use a template in your data.
So everywhere you have a block with {{}} inside the data block, you need to change data to data_template.

Please be informed that you can probably also use a template switch instead of writing multiple automations.

You mean like this:

- id: '1585523916793'
  alias: Enrolar Cortinas
  description: ''
  trigger:
  - entity_id: input_boolean.rollup_curtain
    platform: state
    to: 'on'
  condition: []
  action:
  - data:
      payload_template: '{{ states.input_boolean.rollup_curtain.state }}'
      topic: curtainStatus
    service: mqtt.publish
- id: '1585524161515'
  alias: Desrolar Cortinas
  description: ''
  trigger:
  - entity_id: input_boolean.rollup_curtain
    platform: state
    to: 'off'
  condition: []
  action:
  - data:
      payload_template: '{{ states.input_boolean.rollup_curtain.state }}'
      topic: curtainStatus
    service: mqtt.publish

The switch still doesnt show up onthe dashboard.

Are your state topic and command topic the same?

For the curtains this should be all you need, no automations:

switch:
  - platform: mqtt
    name: curtains
    command_topic: "command_topic"
    state_topic: "curtainStatus"
    payload_on: "1"
    payload_off: "0"

The command_topic should be the topic that opens/closes the curtains when a command is sent to it. The state_topic should be the topic that shows the state of the curtains.
When the switch works, it will send “1” to the command_topic when you turn on the switch and send “0” to the command_topic when you turn off the switch. The switch gets its state from the state_topic.

I also realized your templates don’t make sense, currently it sends the state of the input_boolean as a payload, however you need 1 or 0 as payload, the state of an input_boolean is either ‘on’ or ‘off’, so it will not send the correct payload and therefore your curtain wont change position.

Yeah I dont understand what happened. With all the versions things have gotten messed up. When I started, automations.yaml didnt exist, at least I dont think so or maybe I didnt use it. What I know so far is that the switch doesnt show up for the curtains as it does for the solenoid and kompressor and I dont understand why?

Do you have any errors in the logs?

Yes but I dont see any related to switches.

Line 127 is empty but just before the groups.yaml call:
Screen Shot 2020-03-30 at 9.05.09 AM

and the only thing in the groups.yaml file is:

Coffee_Monitoring:
  name: Coffee Monitor
  view: yes
  entities:
    - sensor.emoncms_nodefortniteh
    - sensor.emoncms_nodefortnitet

which refer to emoncms sensors that used to work but for some reason stopped working.

Let me understand something.

  1. I need to create the entities (switches & input booleans) in the configuration.yaml file, right?
  2. Then I create the automations either in the UI or in the automations.yaml file, right?

Groups as a frontend construct has been deprecated in version 107, remove the line
view: yes
But you are right, has nothing to do with your switch.

To your questions:

  1. Yes.
  2. Yes, the automations you create in the UI will be stored in automations.yaml as well.

Can you please post your full configuration.yaml file, with all sensitive information redacted?

Sure here it is:

homeassistant:
  # Name of the location where Home Assistant is running
  name: Home
  # Location required to calculate the time the sun rises and sets
  latitude: 25.5263
  longitude: -58.0307
  # Impacts weather/sunrise data (altitude above sea level in meters)
  elevation: 90
  # metric for Metric, imperial for Imperial
  unit_system: metric
  # Pick yours from here: http://en.wikipedia.org/wiki/List_of_tz_database_time_zones
  time_zone: America/Bogota
  # Customization file
  customize: !include customize.yaml

# Show links to resources in log and frontend
#introduction:

# Enables the frontend
frontend:

# Enables configuration UI
config:

# Uncomment this if you are using SSL/TLS, running in Docker container, etc.
# http:
#   base_url: example.duckdns.org:8123

# Checks for available updates
# Note: This component will send some information about your system to
# the developers to assist with development of Home Assistant.
# For more information, please see:
# https://home-assistant.io/blog/2016/10/25/explaining-the-updater/
updater:
  # Optional, allows Home Assistant developers to focus on popular components.
  # include_used_components: true

# Discover some devices automatically
discovery:

# Allows you to issue voice commands from the frontend in enabled browsers
conversation:

# Enables support for tracking state changes over time
history:

# View all events in a logbook
logbook:

# Enables a map showing the location of tracked devices
map:

# Track the sun
sun:

# Example configuration.yaml entry
input_boolean:
  notify_home:
    name: Publish MQTT msg
    icon: mdi:car

  power_kompressor:
    name: Kompressor
    icon: mdi:car

  power_solenoid:
    name: Solenoid
    icon: mdi:car

  power_curtain:
    name: Curtains
    icon: mdi:home

# MQTT Switches RPi2 - RPi3
switch:
  - platform: mqtt
    name: kompressor
    command_topic: "test_channel"
    payload_on: "komp-on"
    payload_off: "komp-off"
  - platform: mqtt
    name: solenoid
    command_topic: "test_channel"
    payload_on: "sole-on"
    payload_off: "sole-off"
  - platform: mqtt
    name: power_curtain
    command_topic: "curtainStatus"
    payload_on: "1"
    payload_off: "0"
    
# Sensors
sensor:
  # Weather prediction
  - platform: yr
  
  # Emoncms
  - platform: emoncms
    api_key: mykey
    url: http://www.mydomain.com/emoncms/
    id: 1

# Example configuration.yaml entry configuring HomeKit
homekit:

mqtt:
  broker: 192.168.1.113
  
sonoff:
  username: [email protected]
  password: mypwd
  scan_interval: 60
  grace_period: 600
  api_region: 'us'
  
# Example configuration.yaml entry
device_tracker:
  - platform: bluetooth_le_tracker
  
# Text to speech
tts:
  - platform: google_translate
    service_name: google_say

# Cloud
cloud:

group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml

#panel_iframe:
#  configurator:
#    title: Configurator
#    icon: mdi:wrench
#    url: http://hassio.local:3218
#    
system_health:

Are you sure the topic is correct?
Can you please go to Developer Tools -> MQTT and enter # in the box “Listen to a topic” and press start listening. Then manually control the curtain and post a screenshot of the output in the “Listen to a topic” box here.

Did you restart Home Assistant after adding the switch?
If you go to Developer Tools -> States do you see an entity switch.power_curtain?

i know the mqtt topic is curtainStatus. Ive tested it many ways.

As for the dwitch entity, well, therein lies the rub. Its not there…no matter what i do or how many times i restart hassio, it wont come up.

Does it show up when you change the command_topic to “test_channel”?

Did you try without quoting the payload like this:

  - platform: mqtt
    name: power_curtain
    command_topic: "curtainStatus"
    payload_on: 1
    payload_off: 0

Did you try adding a state_topic like this?

  - platform: mqtt
    name: power_curtain
    command_topic: "curtainStatus"
    state_topic: "curtainStatus"
    payload_on: "1"
    payload_off: "0"

I changed the power_curtain command_topic to “test_channel” and after restarting, woah…a bunch of stuff changed. Not sure if it was because of the test_channel change. Let me try changing it back…
The only thing i did differently this time was that i found an option to Restart Hass in a sprocket wheel on the top left of the Configurator file editor and used that instead of the typical Restart Server option in the Hassio Configuration menu option…

ok so i changed it back to curtainStatus and it still shows up. So Im guessing this option:

Isnt quite the same as this option:

And even now something is off and not completely refreshed because if you take a look at my dashboard, i have:

  1. Cortinas input_boolean… which IS INDEED in my configuration.yaml
  2. Rollup Curtains input_boolean… which IS NOT in my configuration.yaml
  3. Muestra toggle switch… which IS NOT in my configuration.yaml

So something doesnt seem to be refreshing completely…

Did you try refreshing the browser with shift + F5?