Creating automation

Hello everyone.
I need help to create a home automation assistant using broadlink rm.
I created a swicth.
switch 1:
platform: broadlink
host: 192.168.1.4
mac: ‘B4:43:0D:38:62:18’
timeout: 15
switches:
luce:
friendly_name: “Luce Sala”
command_on: '6Qs0AA0hIwsjCwwhIwsNIQ0hD…
command_off: '6Qs0AA0hIwsjCwwhIwsNIQ0h……

I would make sure that given the on command after 20 seconds the off command is activated automatically.

Can it be done? What do I enter and where? Thank you.

If I understood your question right, you want to turn off after the switch is turned on for 20 seconds? You could write an automation with trigger as the state of the switch (to: 'on’), and use for:.

Here is an example: https://www.home-assistant.io/docs/automation/trigger/#state-trigger

Thank you for taking my call.
The trigger of State I think it may work, but I don’t know how to configure it. can you help me?

Here is a sample code:

  - alias: Turn Off After 20 Seconds
    trigger:
      - platform: state
        entity_id:
          - switch.xxx
        to: 'on'
        for: 
		  seconds: 20
    action:
	  - service: switch.turn_off
	    entity_id: switch.xxx

The above automation triggers when the switch state goes to ‘on’ mode for 20 seconds, and it turns off the switch. When you copy the code, you may want to replace xxx with the actual entity_id.

I strongly recommend reading Triggers, Conditions, and Actions.

I plugged everything in configuration yaml file:

BroadLink RM Pro

switch 1:
platform: broadlink
host: 192.168.1.4
mac: ‘B4:43:0D:38:62:18’
timeout: 15
switches:
luce:
friendly_name: “Luce Sala”
command_on: ‘6Qs0AA0hIwsjCwwhIwsNIQ0hDCIMISMLDCIjCwwhIwwMIQwhDCEMISMLDAABViQKIwsjCwwhIwsAAAAA’
command_off: ‘6Qs0AA0hIwsjCwwhIwsNIQ0hDCIMISMLDCIjCwwhIwwMIQwhDCEMISMLDAABViQKIwsjCwwhIwsAAAAA’

  • alias: Turn Off After 20 Seconds
    trigger:
    - platform: state
    entity_id:
    - switch 1
    to: ‘on’
    for:
    seconds: 20
    action:
    - service: switch.turn_off
    entity_id: switch 1

Config error. See dev-info panel for details. What is wrong ?

I am not sure if that is your entire configuration or part of it, Please format the code when pasting here, so that it renders correctly and folks can spot any formatting or indentation issues. To format the code you can use three backtics, hit enter, paste your code, hit enter and type three back ticks. Here is an example

Also, the automation code I pasted above goes into the automations.yaml file. If the code is not properly indented, or placed in wrong place, you might get configuration errors.

‘’’

  • alias: Turn Off After 20 Seconds
    trigger:
    • platform: state
      entity_id:
      • switch.1
        to: ‘on’
        for:
        seconds: 20
        action:
    • service: switch.turn_off
      entity_id: switch.1
      ‘’’
      Submitted automations.yaml

Please try again. This is still not the correct formatting. You used three single quote characters, not three “back tick” characters. I’m not sure about all keyboards, but on mine, it’s the top-left most key, above the Tab key and to the left of the “1” key. You need to format your code correctly so we can see the exact spacing. I’m pretty sure your problem is incorrect spacing.

- alias: Turn Off After 20 Seconds
    trigger:
      - platform: state
        entity_id:
          - switch.1
        to: 'on'
        for: 
		  seconds: 20
    action:
	  - service: switch.turn_off
	    entity_id: switch.1

Submitted automations

# BroadLink RM Pro
switch 1:
  platform: broadlink
  host: 192.168.1.4
  mac: 'B4:43:0D:38:62:18'
  timeout: 15
  switches:
    luce:
      friendly_name: "Luce Sala"
      command_on: '6Qs0AA0hIwsjCwwhIwsNIQ0hDCIMISMLDCIjCwwhIwwMIQwhDCEMISMLDAABViQKIwsjCwwhIwsAAAAA'
      command_off: '6Qs0AA0hIwsjCwwhIwsNIQ0hDCIMISMLDCIjCwwhIwwMIQwhDCEMISMLDAABViQKIwsjCwwhIwsAAAAA'

Submitted configuration.

Grazie

Thanks for the proper formatting. There might be other issues, but one that jumps out is the entity_id of the switch. I believe it should be switch.luce, not switch.1.

1 Like

As @pnbruckner mentioned, the entity_id looks suspicious. Also, what error are you getting? If you can post the complete error message and the source code, that will be great. If you are looking for immediate help, you may join here and post the same https://discord.gg/c5DvZ4e

Config error. See dev-info panel for details.

Where can I find out more information about the error?

I solved

  alias: luce sala
  trigger:
  - platform: state
    entity_id: switch.luce
    to: 'on'
    for: 00:00:20          
  action:
  - service: switch.turn_off

grazie a tutti

1 Like