Hi, I’m new to home assistant. Coming from openhab and liking it so far.
I’m struggling with the following.
I have a PLC where real switches and lights are connected to.
The PLC is master so everything works even when hass is down.
To control a light I have 2 variables on modbus:
Status: actual state of light (on/off) = binary sensor in hass
Control: to toggle the state = switch in hass
The switch always has to follow the state of the binary sensor.
I only want to put the switch on the dashboard, and the switch should always be the actual state of the binary sensor.
Example:
Light is off, i switch on light via switch in the wall, the binary sensor changes to on, the switch in hass also has to change to on.
It works perfectly, but I have about 50 lights so it’s many lines for something simple.
Is there a way to make this a bit more compact and cleaner?
I also can’t figure out how I can put it all in code, I made this in the UI but would like to put it all in a seperate yaml file.
I looked up this link: Automation YAML - Home Assistant
But I can’t get it to work…
Piece of the example below:
# Example of entry in configuration.yaml
automation my_lights:
# Turns on lights 1 hour before sunset if people are home
# and if people get home between 16:00-23:00
- alias: "Rule 1 Light on in the evening"
trigger:
It complains that I can’t use my_lights… Can someone point out why?
This should get your code working, but I think it is not really what you want because it stays in a single file.
# This is very important and I'm not sure if you have this in your configuration.yaml file too.
automation: !include automations.yaml
# Labeled automation block
automation kitchen:
- trigger:
- platform: ...
This could be your file structure:
when you’re using automation: !include_dir_list ./automations in your configuration.yaml
Do you also have an example of multiple automations in 1 file?
I have been fiddling with it for an hour with name and alias properties but I can’t get it to work.
But I would like this piece of code multiple times in the same file… Really can’t get it to work…
Also another question, is it possible to make this like a kind of function I could call and just pass parameters?
Like: modbusSwitch:=updateSwitch(modbusSensor) or updateSwitch(modbusSensor,modbusSwitch)?
This will work only if the last character in the binary_sensor’s name corresponds to the last character of the corresponding switch’s name. In other words, if binary_sensor.wago_sensor3 corresponds to switch.wago_switch3.