Timer control of sonoff s26

Hi,
I haven’t really played too much with automations and my first attempts didn’t meet with much success. I would appreciate someone pointing me in the right direction.
I have 4 sonoff s26 wall sockets. They each have a plug in mozzie zapper.
Each device is in a separate area of the house - the house is a collection of pavilions.
2 of these areas are guest bedrooms.
What i want to do is - from my ha home page

  • select the room where i want the device to turn on (only when guests are staying)
  • when i turn this device on i want it to recognise sunset and sunrise and only turn on the device at sunset, then turn it off at sunrise
    -I know i can set this on the actual device as a schedule but i want to be able to decide when that schedule starts as i don’t want the things turning on when i don’t have guests in there.
    I just get a bit confused when i start looking at triggers, conditions etc.
    Pat

What will “decide” if guests are staying in the room? Will you manually turn on a “virtual switch” inside HA (in reality a helper), or will you use a presence sensor of some sort, or …??

Here’s an idea…
When my kids are home, either one or both, based on their phones with HA installed, a power strip in their bedroom gets powered on which powers on various devices that don’t need power when they are gone.

I have an automation that says “if child1 is home, or if child 2 is home, then turn on outlet”.
I have a 2nd automation that says the opposite, but instead uses an AND statement - “when child 1 leaves AND child 2 leaves, then turn off outlet”.

If you want to manually turn on a virtual switch, then create a helper that says Guest is in Room 1 and turn it on when they get there. Then create an automation that says when helper.guest_is_in_room_1 is on then turn on outlet. And then an opposite automation too.

If you’re going to use a motion sensor, then the automation will say “when motion is detected” then turn on outlet. And then a 2nd automation for when no motion for 10 minutes turn off outlet.

Does that make sense?

Ryan

that does make sense. i didn’t even look at helpers. This sounds like the path i need to go as I can’t do automation because the guests will all be different device id’s. I had considered a kind of bluetooth tab that when we have guests i just move into the room and then the automations kick in on switches etc as you describe for your children.

thanks

Pat

1 Like

So… I made a helper and I successfully linked to an automation to control the ‘on’ part of the switch. How do I go about making it continiue and then turn off at sunrise. I also need it to be able to run this cycle until i toggle the helper boolean again to off.
code

description: ""
trigger:
  - platform: state
    entity_id:
      - input_boolean.kitchen_mozzie_zapper
    from: "off"
    to: "on"
condition:
  - condition: and
    conditions:
      - condition: sun
        after: sunset
action:
  - service: switch.turn_on
    data: {}
    target:
      entity_id: switch.sonoff_1000b89878
mode: single

pat

further to the above. Should I insert a ‘while’ loop.
The while checks to see if the state of the boolean helper button is on then run a script that turns on or off each of the separate devices. I would need a while loop, script and boolean helper button for each device?
Pat

I know i’m only responding to myself here but happy for other input. :smirk:
I think I have got somewhere - if you see an error in my code please let me know.

alias: kitchen mozzie zapper
description: ""
trigger:
  - platform: state
    entity_id:
      - input_boolean.kitchen_mozzie_zapper
    to: "on"
    from: "off"
condition:
  - condition: sun
    after: sunset
action:
  - type: turn_on
    device_id: 17491f51e645f2a3441f4f8224f52200
    entity_id: switch.sonoff_1000b89878
    domain: switch
condition:
  - condition: sun
    after: sunrise
action:
  - type: turn_off
    device_id: 17491f51e645f2a3441f4f8224f52200
    entity_id: switch.sonoff_1000b89878
    domain: switch
mode: single

Next challenge is - with each of these devices they have an insert that heats and repels mozzies. It has a finite life. I would like to be able to track how long each device is switched on and then send an alert to me when it reaches a certain number of hours. Any pointers?
Pat