#Help turning on/off a switch depending on the outside temperature

1 messages Β· Page 1 of 1 (latest)

onyx hawk
#

Hi all,

My girlfriend likes her bed heated when it's cold outside. But not too long and repetition is needed. So: I want to make an automation that checks the outside temperature. If it's below 2C the heating should turn on. But only between midnight and 6am. But only for 15 minutes and then 45 off (so 15 minutes per hour). Then repeat.

So, I created the automation in the next message.

Result (yes, it was below 2C last night): it turned on at 2:47 and didn't turn off... I think the error is somewhere in the repeat, but I can't find out what I did wrong?

rough cedarBOT
#

@onyx hawk To format your text as code, enter three backticks on the first line, press Enter for a new line, paste your code, press Enter again for another new line, and lastly three more backticks.
```yaml
example: here
```
Don't forget you can edit your post rather than repeatedly posting the same thing.

onyx hawk
#
description: ""
triggers:
  - trigger: numeric_state
    entity_id:
      - weather.forecast_home
    attribute: temperature
    below: 2
conditions:
  - condition: time
    after: "00:00:00"
    before: "06:00:00"
    weekday:
      - sun
      - mon
      - tue
      - wed
      - thu
      - fri
      - sat
actions:
  - action: switch.toggle
    metadata: {}
    data: {}
    target:
      entity_id: switch.tz3000_kdi2o9m6_ts011f_switch
  - delay:
      hours: 0
      minutes: 15
      seconds: 0
      milliseconds: 0
  - action: switch.turn_off
    metadata: {}
    data: {}
  - delay:
      hours: 0
      minutes: 45
      seconds: 0
      milliseconds: 0
  - repeat:
      until:
        - condition: time
          after: "00:00:00"
          before: "06:00:00"
          weekday:
            - sun
            - mon
            - tue
            - wed
            - thu
            - fri
            - sat
      sequence: []
mode: single
delicate cape
delicate cape
#

currently it looks like its:

toggling switch
wait 15 mins
turn off NOTHING
wait for 45 mins
repeat DOING NOTHING until time condition fails
unborn garden
#

But the trigger is already flawed. You mixed up trigger (when you want it to happen) and condition (what need to be true). So trigger is at 0:00 and the condition is that is is < 2, then start repeating

#

But, I'm not a fan of long running automations. You know all the possible moments you want to act. Just trigger then.

alias: Bed astrid 15-45
description: ""
triggers:
  - trigger: time_pattern
    minutes: "0"
    hours: "*"
    id: turn on
  - trigger: time_pattern
    minutes: "45"
    hours: "*"
    id: Turn off
conditions:
  - condition: time
    after: "00:00:00"
    before: "06:00:00"
actions:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - turn on
          - condition: numeric_state
            entity_id: weather.forecast_home
            below: 2
        sequence:
          - action: switch.turn_on
            metadata: {}
            data: {}
            target:
              entity_id: switch.tz3000_kdi2o9m6_ts011f_switch
      - conditions:
          - condition: trigger
            id:
              - Turn off
        sequence:
          - action: switch.turn_off
            metadata: {}
            data: {}
            target:
              entity_id: switch.tz3000_kdi2o9m6_ts011f_switch
mode: single
delicate cape
#

or perhaps something like this:

description: ""
mode: single
triggers:
  - trigger: time_pattern
    hours: /1
    id: top_of_hour
  - trigger: time_pattern
    hours: /1
    minutes: "15"
    id: 15_after_hour
conditions:
  - condition: time
    before: "06:16:00"
actions:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - top_of_hour
          - condition: numeric_state
            entity_id: weather.forecast_home
            attribute: temperature
            below: 2
        sequence:
          - action: switch.turn_on
            metadata: {}
            data: {}
            target:
              entity_id: switch.tz3000_kdi2o9m6_ts011f_switch
      - conditions:
          - condition: trigger
            id:
              - 15_after_hour
        sequence:
          - action: switch.turn_off
            metadata: {}
            data: {}
            target:
              entity_id: switch.tz3000_kdi2o9m6_ts011f_switch

would check temp at hours 0->6 and switch on if below 2
then at quarter past hours 00:15 -> 06:15 it will switch off (if its already off it will do nothing)

#

don't worry @onyx hawk, between myself and @unborn garden and I am sure we can keep your girlfriends bed warm...

#

Joke was too easy to miss out on... πŸ™‚

unborn garden
#

πŸ˜‹

onyx hawk
unborn garden
#

But seems like @delicate cape was thinking alone the same lines as I did πŸ˜…

onyx hawk
delicate cape
#

as mentioned above, in general "long running" automations are not recommended. getting it to trigger when an action is needed is a better option.

onyx hawk
#

I'm not good at Yaml, so I'm trying to replicate what you're saying in the visual editor...

#
description: ""
triggers:
  - trigger: numeric_state
    entity_id:
      - weather.forecast_home
    attribute: temperature
    below: 2
conditions: []
actions:
  - repeat:
      until:
        - condition: time
          after: "00:00:00"
          before: "06:00:00"
          weekday:
            - sun
            - mon
            - tue
            - wed
            - thu
            - fri
            - sat
      sequence:
        - type: turn_on
          device_id: 885655371789e71e4e6612024b949d35
          entity_id: e21544eabea77139190a81a6c4e1e161
          domain: switch
        - delay:
            hours: 0
            minutes: 15
            seconds: 0
            milliseconds: 0
        - action: switch.turn_off
          metadata: {}
          data: {}
          target:
            entity_id: switch.tz3000_kdi2o9m6_ts011f_switch
        - delay:
            hours: 0
            minutes: 45
            seconds: 0
            milliseconds: 0
mode: single
#

so it'll only run when it's below 2C and I moved the action inside the repeat

delicate cape
#

you can switch back and forth between yaml and visual. so can switch to yaml and paste then switch back to visual

onyx hawk
#

I never knew!

#

I've now installed Michael's version

#

I would have never thought of doing it that way, but it's exactly what I was looking for

#

I just don't see where it says midnight

#

or does it automatically start at 0h00?

delicate cape
#

at midnight it will trigger because its an hour and then check thats its before 0616 which 0000 is

onyx hawk
#

aaaahhh

delicate cape
#

it will trigger every hour but only do something before 0616

onyx hawk
#

I get it now

unborn garden
onyx hawk
#

I've changed it to 4 degrees, since it'll be 3 degrees this night πŸ˜‰

#

Thank you both, let's see if she's happy tomorrow morning! hahaha

unborn garden
delicate cape
#

once you get the ideal of how to use the tools and learn some ways to approach things then automations get easier

delicate cape
onyx hawk
#

The bad thing is, that I've been a user for like 4 years, but here it was just too much at the same time πŸ™‚

unborn garden
#

And tip for the time condition, leaving weekday blank is the same as adding them all πŸ˜„

onyx hawk
delicate cape
#

I imagine my setup can be cleaned up a bit but it was quick and dirty. and removed some ambiguity

unborn garden
delicate cape
#

but technically you are correct

unborn garden
onyx hawk
#

Weekdag...

#

that's the one I was doubting about πŸ™‚

#

But of course you're absolutely right

delicate cape
#

now you just need to detect switch on failure and send you an alert to commence emergency 15 minute warm up cuddle.

onyx hawk
#

Hahahahahahaha

unborn garden
#

but yeah, just to save work you can leave it blank πŸ™‚

#

hehe

onyx hawk
#

I had already created two buttons on the Streamdeck next to her bed (used to control the lights) that turned on the heating for 15 or 60 minutes. But I wanted a good automation

delicate cape
#

these kind of simple but extremely useful automations are really the core of a smart home πŸ™‚

unborn garden
#

But just my two cents, I think I would switch to a 5min on and 15min off scheme. That would reduce the hourly inferno

onyx hawk
#

Yeah, we'll have to finetune it. It's a first step. I'll hear it when she's unhappy for sure πŸ˜‰

#

At least I can now easily change it

delicate cape
#

or add a bed temp sensor and do it on demand...

onyx hawk
#

I have a busy weekend, please don't put things in my head hahaha

delicate cape
#

there is a million ways to make it more complicated πŸ˜›

onyx hawk
#

I'm sure and I wish you good luck with that. It's been difficult enough for me hahaha

unborn garden
#

hehe, here it turns on for 10 minutes before we enter bed if it's cold and we enter the bathroom after 21:00 πŸ˜…

onyx hawk
#

I don't have a heating, my g/f (latina) can't live without it...

unborn garden
#

We have a single one but across at the foot end. Just to take the edge off