Hello Guys,
i want to turn on a light if a switch (GPIO on my Raspberry) turned to on.
Here is my Code:
switch pi:
platform: rpi_gpio
ports:
16: Bewegungsmelder
18: Alarm
alias: 'Turn alarm LED on'
trigger:
- platform: state
entity_id: pi.Bewegungsmelder
from: 'off'
to: 'on'
condition:
- condition: state
entity_id: pi.Bewegungsmelder
state: 'on'
action:
<TURN ON Alarm (Port 18)>
First of all:
Is my syntax right and can i do it in my configuration.yaml (is that working)?
and if yesā¦ how can i write my Action? (This Part: <TURN ON Alarm (Port 18)>)
Second:
I get Errors with my command āhass --script check_configā if i put my code in the yaml file. Line 82 is the Column ātā in ātrigger:ā.
2017-07-09 12:48:32 ERROR (Thread-1) [homeassistant.util.yaml] while parsing a block mapping
in "/home/homeassistant/.homeassistant/configuration.yaml", line 1, column 1
expected <block end>, but found '<block mapping start>'
in "/home/homeassistant/.homeassistant/configuration.yaml", line 82, column 3
2017-07-09 12:48:32 ERROR (MainThread) [homeassistant.bootstrap] Error loading /home/homeassistant/.homeassistant/configuration.yaml: while parsing a block mapping
in "/home/homeassistant/.homeassistant/configuration.yaml", line 1, column 1
expected <block end>, but found '<block mapping start>'
in "/home/homeassistant/.homeassistant/configuration.yaml", line 82, column 3
You dont need the hyphen for the platform unless there are multiple. This may not be the exact issue though.
I see some spacing issues too. Also when you added the pi ports to you config it should have created entities which you can check in the dev tools. You can put your automation in the config but there should be the automation header.
Your switch should look like this with all switch platforms under it.
Your automation could look like this with all automation below it.
automation:
- alias: 'Turn alarm LED on'
trigger:
platform: state
entity_id: pi.Bewegungsmelder
from: 'off'
to: 'on'
condition:
- condition: state
entity_id: pi.Bewegungsmelder
state: 'on'
action:
service: switch.turn_on
entity_id: switch.alarm_switch # Use the actual name of your switch here
@PtP Thank you for the help, the code is now correct.
If i now turn on the āBewegungsmelderā switch, the āAlarmā Switch does not turn on. Why?
Does this code not trigger it? Manual it turns on if i use the switchbutton of āAlarmā.
# CONF RPI GPIO PINs
switch pi:
platform: rpi_gpio
ports:
16: Bewegungsmelder
18: Alert
# CONF Alarm test
automation:
- alias: 'Turn alarm LED on'
trigger:
platform: state
entity_id: pi.Bewegungsmelder
from: 'off'
to: 'on'
condition:
- condition: state
entity_id: pi.Bewegungsmelder
state: 'on'
action:
service: switch.turn_on
entity_id: pi.Alert #Port 18
This is my Code. Without Problems i can start Hass. But the Switch is not turning to on. @keithh666@PtP
So decided for the Redundant solution because i want to build in the Future more with sensors and so on. A little bit practice is good. (Like if light on then send SMS or Push message)
No Event Triggered?