Can someone please help me with 3 more automations?

I need help with these three automations.

  1. Increasing / Decreasing AC Temperature by an increment / decrement of 1.
  2. Retaining the attributes of an rgbw led controller, then changing the attributes for a few seconds & then returning the attributes back to the retained state. Example the light is red color at 50% brightness. If a button is preseed then the light should change to green at 100% brightness for 10 seconds, then it should change back to red at 50% brighntness.
  3. Automation that can cycle between 5 preset colors.

Post what you tried (properly formatted).

Post what didn’t work with the things you tried.

Somebody can probably help you from there.

I haven’t exactly tried anything as I am total noob at HA. But below I am mentioning what I think I want from these automation:

  1. Increasing / Decrease Temperature of my Samsung AC: Currently I can set a specific temperature for my samsung AC via the climate service. So I want an automation which when triggered can either increase / decrease the temperature by an increment/decrement of 1. So I think this automation should first fetch the current temperature of my samsung ac & then based on the automation should increase / decrease the temperaure by 1.
    To change the temperature of my ac to 26, below is the code:
mode: single
trigger:
  - platform: state
    entity_id:
      - sensor.sonoff_mainbedroomr5
    to: button_1_single
action:
  - service: climate.set_temperature
    data:
      temperature: 26
    target:
      device_id: MainBedroomAC

So the automation should be triggered when the state of the MainBedroomR5 sensor changes to button_1_single.
Then the automation should fetch the Temperature state of the AC.
And then whatever the Temperature was it should increment it by 1.

I can see the Temperature State of my AC by going to Developer Tools > State > MainBedroomAC (Entity) > Temperature.
But I don’t understand how I can fetch this value in an automation & then increment it by 1.

  1. An automation that can be triggered when the state of the MainBedroomR5 sensor changes to button_1_double.
    I want this automation should first fetch the current state of my MainBedroomLED (Shelly RGBW2 Controller); suppose it fetches that the RGBW was set to Cyan Color at 50% Brightness without any coolor changing effect. Then it should change the state of the LED to my desired color, brightness & effect for 10 seconds i.e. Red Color at 30% Brightness without any color changing effects.
    After the 10 seconds has passed the LED state then should return back to its old state i.e. Cyan Color at 50% Brightness. Below is the code that can be used to set the state of the LED to the above mentioned color:
mode: single
trigger:
  - platform: state
    entity_id:
      - sensor.sonoff_mainbedroomr5
    to: button_1_double
action:
  - service: light.turn_on
    data:
      rgbw_color:
        - 255
        - 0
        - 0
        - 0
      brightness_pct: 30
    target:
      device_id: MainBedroomLED
  - delay:
      hours: 0
      minutes: 0
      seconds: 10
      milliseconds: 0

I can’t figure out the part of the automation that fetches the current state of the LED & store it, then once the above automation runs (along with the 10s delay), the state of the LED should change back to the stored (previous) state.

action:
  - service: climate.set_temperature
    data:
      temperature: "{{ state_attr('climate.bedroom', 'temperature') | float(21) + 1 }}"
    target:
      entity_id: climate.bedroom

EDIT

Correction. Replaced states('climate.bedroom') with state_attr('climate.bedroom', 'temperature')

1 Like

Create a snapshot scene (containing just the light) just before the light.turn_on service call. Restore the snapshot scene after the delay statement.

Reference: Creating scenes on the fly

action:
  - service: scene.create
    data:
      scene_id: before
      snapshot_entities: light.bedroom
  - service: light.turn_on
    data:
      rgbw_color:
        - 255
        - 0
        - 0
        - 0
      brightness_pct: 30
    target:
      entity_id: light.bedroom
  - delay: '00:00:10'
  - service: scene.turn_on
    target:
      entity_id: scene.before
1 Like

This code already has predefined temperature. Is there any way to fetch the current temperature & then increment it by 1?

That’s what this does:

temperature: "{{ state_attr('climate.bedroom', 'temperature') | float(21) + 1 }}"

It takes the current target temperature and increments it by 1.


EDIT

Correction. Replaced states('climate.bedroom') with state_attr('climate.bedroom', 'temperature')

1 Like

This worked perfectly. Thanks.

In float(21), what does 21 mean?
Before running this automation my ac temp was 29. When I use this automation, it sets the temp to 22 which is 21+1. Its not fetching the current temp.

You’re correct and it’s due to my mistake.

I have corrected the example I posted above. I replaced this (which doesn’t get the target temperature):

states('climate.bedroom')

with this which gets the value of the temperature attribute:

state_attr('climate.bedroom', 'temperature')
1 Like

Yes, that worked. Thanks. BTW can you please tell me what does the float(21) mean in the code?

The 21 in float(21) is the default value float will report if float is unable to convert the value it is given.

For example, if the result of states('sensor.example') is unavailable then the following template will report 21.

 {{ states('sensor.example') | float(21) }}
2 Likes
  1. Do you know how to perform this automation?
alias: example color change
trigger:
  - platform: state
    entity_id: input_boolean.color_changer
    to: 'on'
action:
  - variables:
      colors:
        - red
        - green
        - gold
        - blue
        - orange
  - repeat:
      while: "{{ repeat.index <= colors | count and is_state('input_boolean.color_changer', 'on') }}"
      sequence:
        - service: light.turn_on
          target:
            entity_id: light.first
          data:
            color_name: "{{ colors[repeat.index - 1] }}"
        - delay:
            minutes: 1
mode: single

Sorry I wasn’t more clear about what automation that I wanted to run.
I want an automation that changes color of my Shelly RGBW2 Controller from one color to another upon a button press i.e. the button_3_single state of an R5 Scene Controller.
So, the trigger should be,

trigger:
  - platform: state
    entity_id:
      - sensor.sonoff_bedroomr5
    to: button_3_single

So the actions should be as follows:
action:
RED at 100%

  - service: light.turn_on
    data:
      rgbw_color:
        - 255
        - 0
        - 0
        - 0
      brightness_pct: 100
    target:
      device_id: bedroomled

BLUE at 100%

  - service: light.turn_on
    data:
      rgbw_color:
        - 0
        - 255
        - 0
        - 0
      brightness_pct: 100
    target:
      device_id: bedroomled

GREEN at 100%

  - service: light.turn_on
    data:
      rgbw_color:
        - 0
        - 0
        - 255
        - 0
      brightness_pct: 100
    target:
      device_id: bedroomled

WHITE at 100%

  - service: light.turn_on
    data:
      rgbw_color:
        - 0
        - 0
        - 0
        - 255
    target:
      device_id: bedroomled

Each time when I single press the Button 3 of my R5, it should change color. Suppose my RGBW2 controller color is set to White at 25% Brightness. When I Single Press the Button 3 of my BedroomR5 it should change its color to Red at 100% Brightness. Then if I single press the same button again it should change the color to Blue at 100% Brightness, then again to Green at 100% & then again to White at 100%.

The following State Trigger will trigger when the sensor’s state changes from some value to button_3_single.

trigger:
  - platform: state
    entity_id:
      - sensor.sonoff_bedroomr5
    to: button_3_single

If you press the same button twice, the sensor’s value won’t change the second time (because the previous and new values are identical) so because there’s no state-change it won’t trigger the State Trigger.

You can check its behavior using this simple automation.

alias: button test
trigger:
  - platform: state
    entity_id:
      - sensor.sonoff_bedroomr5
    to: button_3_single
condition: []
action:
  - service: notify.persistent_notification
    data:
      title: "{{ now().timestamp() | timestamp_custom() }}"
      message: Button pressed.

Press the button once and the automation will post a persistent notification. Press the same button again and see if another notification is produced or nothing happens.

Single Pressing the Button 3 two times i.e. 3-4 seconds gap between the presses created two notifications.

OK, that’s interesting so it means the sensor’s state doesn’t remain the same after the button is released. What is the sensor’s state immediately after the button is released?