Some help with first start config

Hello all,

I have add this in my action.yaml is there a way to make this much easier?
I want change from Domotic to HA. Have lot of scripts running that do checks before actions:

I understand the condition part little bit. But the action part I need have some if this then that statement as well. Can someone help me with some simple way to do i.f.t.t.t. part inside action?

#TEST 1                                                                                                                         
- alias: Test                                                                                                                   
  initial_state: true
                                                                                                                                
  trigger:                                                                                                                      
    platform: state                                                                                                             
    entity_id: light.balcony_all                                                                                                
    from: 'off'                                                                                                                 
    to: 'on'                                                                                                                    
                                                                                                                                
  condition:                                                                                                                    
    - condition: state                                                                                                          
      entity_id: sun.sun                                                                                                        
      state: 'below_horizon'                                                                                                    
                                                                                                                                
  action:                                                                                                                       
    - service: light.turn_on                                                                                                    
      data:
        entity_id: light.dressoir_1                                                                                 
        kelvin: 3000
        brightness: 255
    - service: light.turn_on
      data:
        entity_id: light.dressoir_2
        kelvin: 3000                                                                                                            
        brightness: 255
    - service: light.turn_on
      data:                                                                                                                     
        entity_id: light.dressoir_3
        kelvin: 3000
        brightness: 255

When for example a light is already on then light.dressoir_1 must be red instead of kelvin. Or when date is first xmas day then light.dressoir_2 must be green. (example)

I think you should read about Service templating.

1 Like

Thanks, tried a simple test to understand but what I try its not working:

- alias: Test                                                                                                                                  
  initial_state: true                                                                                                                          
                                                                                                                                               
  trigger:                                                                                                                                     
    platform: state                                                                                                                            
    entity_id: light.balcony                                                                                                                   
    from: 'off'                                                                                                                                
    to: 'on'                                                                                                                                   
                                                                                                                                               
  action:                                                                                                                                      
    service: light.turn_on                                                                                                                     
    entity_id: light.dressoir1
    data_template:                                                                                                                             
      rgb_color: > 
      {% if is_state('light.hall'), 'on' %}                                                                                 
        [150,255,142]                                                                                                               
      {% elseif is_state('light.hall'), 'off' %}                                                                          
        [250,255,142]
      {% endif %}

Here I turn on light.balcony. when light.hallway is on then light.dressoir must go on with color 1 if light.hallway is off then light.dressoir must go on with color 2.

If this is working then I will understand more how yaml script is working. In Domoticz it works different


What about?

  action:                                                                                                                                      
    service: light.turn_on                                                                                                                     
    data_template:                                                                                                                     
      entity_id: light.dressoir1        
      rgb_color: > 
      {% if is_state('light.hall'), 'on' %}                                                                                 
        [150,255,142]                                                                                                               
      {% elseif is_state('light.hall'), 'off' %}                                                                          
        [250,255,142]
      {% endif %}

Didn’t work as well

With this I don’t get any errors when I test configuration. But the action is not working

- alias: Test                                                                                                                                  
  initial_state: true                                                                                                                          
                                                                                                                                               
  trigger:                                                                                                                                     
    platform: state                                                                                                                            
    entity_id: light.balcony                                                                                                                   
    from: 'off'                                                                                                                                
    to: 'on'                                                                                                                                   
                                                                                                                                               
  action:                                                                                                                                      
    service: light.turn_on                                                                                                                     
    data_template:                                                                                                                             
      entity_id: light.dressoir1
      rgb_color: > 
        {% if is_state('light.hall', 'on') %}                                                                            
          [150,255,142]                                                                                                          
        {% else  %}                                                                                                                            
          [250,255,142]                                                                                                                      
        {% endif %}

When I test the if part in “dev-template” then I get the right output


Hmm, looking at a template that i use for random rgb_color i did put the numbers in single quotes.

      - service: light.turn_on
        data_template:
          entity_id: '{{ states.input_select.schreibt_milights.state }}' 
          rgb_color: ['{{ states.sensor.random_rgb.state.split(",")[0] }}', '{{ states.sensor.random_rgb.state.split(",")[1] }}', '{{ states.sensor.random_rgb.state.split(",")[2] }}']
          brightness: 140

Maybe?

['150','255','142']

Thanks for all the ideas but also didn’t work out.

In Domoticz you have a script like this:

return {
    active = true,
    on = {
    
    devices = {SwitchToilet},
    },
    
    --logging = {marker = 'SWITCHES Toilet Control ' ..Version..'......'},
    execute = function(domoticz, device)

    if (domoticz.devices(SwitchToilet).active and not domoticz.devices(SceneGoodnight).active) then
        domoticz.helpers.RGB(domoticz,BulbToiletAll,nil,nil,nil)
        
    elseif (domoticz.devices(SwitchToilet).active and domoticz.devices(SceneGoodnight).active) then  
        domoticz.helpers.On(domoticz,BulbToiletAll)
        
    elseif (not domoticz.devices(SwitchToilet).active) then
        domoticz.helpers.Off(domoticz,BulbToiletAll,nil,nil)
    end
    --domoticz.log('------------------------==<[ SWITCH '..device.idx..' On/Off ]>==--------------------', domoticz.LOG_FORCE)
end
}

When SwitchToilet and not SceneGoodnight are active then turn on BulbToiletAll with RGB color. Nil means nothing then it use default RGB color stored in a global_data file

This wat of script seems much easier
 :slight_smile: but want learn the YAML script
 at the end probably I can do much more then what I can do with Domoticz at this moment.

Also Integration of mitt, homekit, and lots of devices are supported already makes me to switch


But first need to let work this


Test it with entity_id and this is working perfect

- alias: Test                                                                                                                                  
  initial_state: true                                                                                                                          
                                                                                                                                               
  trigger:                                                                                                                                     
    platform: state                                                                                                                            
    entity_id: light.balcony                                                                                                                   
    from: 'off'                                                                                                                                
    to: 'on'                                                                                                                                   
                                                                                                                                               
  action:                                                                                                                                      
    service: light.turn_on                                                                                                                     
    data_template:                                                                                                                             
      entity_id: >                                                                                                                             
        {% if is_state('light.hall', 'on') %}
          light.dressoir1
        {% else  %}
          light.dressoir2
        {% endif %}
      rgb_color: [150,255,142] 

So have to figure out why rob_color: > is not working


This is working also:
rgb_color: [’{{ “{0:d}”.format(range(0, 255)|random) }}’,
‘{{ “{0:d}”.format(range(0, 255)|random) }}’,
‘{{ “{0:d}”.format(range(0, 255)|random) }}’]

Found this: