I’m trying to achive the automation as described below, but it’s much harder than I expected.
I have a room with 2 double wall switches, a PIR and a dimmer.
The left button of double wall switch is used to turn on the light at 100% and the right button is to turn on the light for 10%.
The second wall switch has the exact same function.
If any of the wall switch button is turned of, the light should go out
Next to that I have a PIR in the same room. If the PIR is triggerd after sun-set, the light should go on for 2 minutes at 10%.
I have a fresh installd RPi 3, switches, PIR and dimmer (all RF 433Mhz)) are all defined in the configuration.yaml
My automation.yaml is quite straight forward.
Problem: I can’t switch off the light using wall switch B if the light is turned on with wall switch A.
It seems to remember the state of the wall switches because in some ocations I can’t switch on the lights.
I am using Sonoff Wall switches via MQTT this should get your started with the basic switching.
Once you got that sorted you can look at dimming at 10%
Can you please post your code using the code format button . Instructions at the top of the page. it really helps to verify the formatting.
But a couple of things from trying to review you code
It looks like you have two different automations that use the same trigger, and none of them have any conditions. Both light.sk_deur_r and light.sk_bed_l are set as triggers. One for 100% and one for 10%.
You can just use light.turn_off and light.turn_on instead of homeassistant.turn_on/off. homeassistant.turn_on/off is most useful when you have a group of different types of entities, like lights and switches. that you want to turn on/off with one command.
it’s not only hard, it’s also complex what you’re trying to achieve. for example: if you manually turn on the light at night and move in the room, the motion sensor will dim your lightl. so you’ll need a condition checking the state of the light (brightness = 256?). if you set a timer to turn off the light after 2 minutes (i don’t see an automation for that in your code yet), it might also turn off a manually turned on light. i also wonder how you determine wheter a switch is turned on or off? my lightswitches are either rockers that toggle the light state or push buttons. push buttons would work as dedicated on/off switches, but rockers always toggle lights. if you use push-buttons in my experience it’s better to catch push events instead of states to trigger automations.
also 10% brightness in yaml would be brightness_pct: 10.
what i would do is set up the night light automation with appropriate conditions, …
- condition: sun
after: sunset
… starting a script with a two minute delay. the automations to catch the switch events should not only toggle the light, but also stop the timer script, so that the timer won’t turn off the manually switched on light.
So what happens if you press the a “right” switch ON. The light turns on to 100%, then you press a left switch “ON” does it turn to 10%? At that point one left switch is on, and one right switch is on, then you press the second right switch to ON, does it go back to 100%,then you press the last left switch on ON, does it go back to 10%. Now all 4 switches are ON, pressing ON for any of them should do Nothing, right? Now press any of them to OFF. The dimmable lamp should go off, but the other three switches are still “on”, that’s the issue, you want to turn off all of the switches as well, when anything is turned off
Right,
when I press wall switch A Right ON -> light 100%
when I press wall switch A Left ON -> light 10%
when I press wall switch B Right ON -> light 100%
when I press wall switch B Left ON -> 10%
I want to use the ON state mixed in every combination and/or order.
To switch the light OFF I want to press random wall switch OFF
this is what I have now for automation.yaml
- alias: SK licht aan 100pct
initial_state: 'off'
trigger:
- entity_id: light.SK_Bed_R
platform: state
to: 'on'
- entity_id: light.SK_Deur_R
platform: state
to: 'on'
condition: []
action:
- service: light.turn_on
data:
entity_id: light.lamp_slaapkamer
brightness: 254
- alias: SK licht uit
trigger:
- platform: state
entity_id: light.SK_Deur_R
to: 'off'
- platform: state
entity_id: light.SK_Bed_R
to: 'off'
action:
service: homeassistant.turn_off
entity_id: light.SK_Bed_R, light.SK_Deur_R, light.SK_Bed_L, light.SK_Deur_L
- id: '1552174152495'
alias: Slaapkamer 10%
trigger:
- entity_id: light.SK_Deur_L
platform: state
to: 'on'
- entity_id: light.SK_Bed_L
platform: state
to: 'on'
condition: []
action:
- service: light.turn_on
data:
entity_id: light.lamp_slaapkamer
brightness: 10
with this automations.yaml:
light.sk_bed_l ON results in light on 10%
light.sk_bed_l OFF does not switch off light
light.sk_bed_r ON does not turn on light
light.sk_bed_r OFF does not switch off light (it was not turned on in the first place).
So you have a wall switch with 4 buttons like this: 1 | 2 3 | 4
and you want to map the buttons as such:
1 = 100% brightness
2 = 10% brightness
3 = off
4 = off
watch the events in HA and look for the event that occurs when you click a button. Rewrite the automation with “platform: event” as your trigger rather than state. This way, even if your left switch is already current state off, HASS should still see some event on the switch… maybe it will come in with type = ‘click’ (xiaomi use this), or maybe a service = turn_off command can be seen.
I map my harmony and xiaomi buttons this way, even if the switch they are controlling is set to off, I still see an event for sending the turn_off command from the harmony remote, and use that event as a trigger in my automation.
2019-03-14 22:28:23 ERROR (MainThread) [homeassistant.config] Invalid config for [automation]: expected dict for dictionary value @ data[‘trigger’][0][‘event_data’]. Got None
extra keys not allowed @ data[‘trigger’][0][‘entity_id’]. Got ‘switch.sk_bed_l’. (See /config/automations.yaml, line 0). Please check the docs at https://home-assistant.io/components/automation/
extra keys not allowed @ data[‘trigger’][0][‘entity_id’]. Got ‘switch.sk_bed_l’. (See /config/automations.yaml, line 0). Please check the docs at https://home-assistant.io/components/automation/
extra keys not allowed @ data[‘trigger’][0][‘entity_id’]. Got ‘switch.sk_bed_l’. (See /config/automations.yaml, line 0). Please check the docs at https://home-assistant.io/components/automation/
Looking at “button_pressed” … is there some info in HA logs showing which of the 4 buttons was pressed? that info will go in the condition clause I think