Can someone please help me with 3 more automations?

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?

I think the Sonoff’s R5 Scene Controller is a state less device. I mean when I press a button on my R5 it shows in the log as “Main Bedroom R5 changed to button_3_single
7:43:07 AM - 2 hours ago”.
But when I pressed the same button again, it just shows “Main Bedroom R5
7:43:08 AM - 2 hours ago”.
Although I have used the same button on my R5 to toggle switch & it successfully toggles the switch even if I single press the desired button once & then again within the next 2-3 seconds if I press the same button again, it succesddfully toggles the switch again.


scrsht3

Go to Developer Tools > States and observe how the state value of sensor.sonoff_bedroomr5 changes when you press the button.

When I press any button on my R5 it shows the exact button that I pressed & then it disappears.
Example when I Single Press the Button 3 on my R5, it shows button_3_single for a second then the state goes blank. BTW it is being able to detect each button single press within 1.5s of each press.

Create an Input Select containing the names of the colors want:

  • red
  • blue
  • green
  • white

Then create the following automation:

alias: color changer
trigger:
  - platform: state
    entity_id:
      - sensor.sonoff_bedroomr5
    to: button_3_single
condition: []
action:
  - service: light.turn_on
    data:
      color_name: "{{ states('input_select.colors') }}"
      brightness_pct: 100
    target:
      device_id: bedroomled
  - service: input_select.select_next
    target:
      entity_id: input_select.colors

EDIT

Correction. Added missing quote.

1 Like

I’m unable to create input_select because there is no input select option under Helpers. I checked my configuration.yaml file & it has default_config:
But because i was not seeing the input select option under the helpers; i searched online & it said that if it was deleted them i should add input_select: to my yaml file. I did that & checked the config and restarted. But i still can’t see the input select. Attaching screenshot of the helper section.


It’s the one called “Dropdown” in the Helpers menu.

For reasons unknown to me, some Helpers are named differently in the UI from their documented integrations. :man_shrugging:

1 Like

Oh. Thanks for pointing that out. BTW using the code worked for me. Another thing the code that you posted has a small mistake;
color_name: "{{ states(input_select.colors') }}"
It should be;
color_name: "{{ states('input_select.colors') }}"
I want to ask another thing is there any way to assign each color different brightness level. Example: Red at 80%, Green at 60%, Blue at 40%, etc.?

Corrected.

Yes, but it changes the automation significantly. Are there any other features you want to add because it’s more efficient (for me) to know all of the requirements in advance.

1 Like

No more extra features. I just want to be able to assign cutom brightness level to indivisual colors.