Automation MQTT trigger to ESP2866

Hello, I have been working on this for some time and I could really use some help.
In hassio I have created a binary sensor that communicates with a light sensor that can go into “isdark” state if the lux goes below 100.
I then tried add an automation that when “isdark” activates it sends and on state to the EspixelStick and have lights come on. I can get my “isdark” state to on and I can manually turn on lights but can’t get lights to trigger from “isdark”.
Below is parts of my config.yaml

#espixelstick subnet 110
  - platform: mqtt
    name: "PixelStick01"
    state_topic: "matrix/esps/light/status"
    command_topic: "matrix/esps/light/switch"
    brightness_state_topic: "matrix/esps/brightness/status"
    brightness_command_topic: "matrix/esps/brightness/set"
    rgb_state_topic: "matrix/esps/rgb/status"
    rgb_command_topic: "matrix/esps/rgb/set"
    brightness: true
    flash: true
    rgb: true
    optimistic: false
    qos: 0
	
	sensor:
#Light sensor
  - platform: mqtt  
    state_topic: "bruh/sensornode1"  
    name: "SN1 LDR"
    ##This sensor is not calibrated to actual LUX. Rather, this a map of the input voltage ranging from 0 - 1023.
    unit_of_measurement: "LUX"  
    value_template: '{{ value_json.ldr }}'  
    
# Binary Sensors
binary_sensor:
  - platform: threshold
    name: isdark
    entity_id: sensor.sn1_ldr
    lower: 100
    hidden: true
	
#Groups
group:  
  sensor_node_1_card:  
    name: Sensor Node 1  
    entities:  
      - sensor.sn1_temperature  
      - sensor.sn1_humidity  
      - sensor.sn1_ldr  
      - light.sn1_led
	
automation:
- alias: EspixelStick110 On       
  trigger:                               
    - platform: state                    
      entity_id: binary_sensor.isdark    
      to: 'on'                           
  condition:                             
    - condition: state                   
      entity_id: binary_sensor.isdark    
      state: 'on'                        
  action:                                
    - service: mqtt.publish              
      data_template:                     
        topic: "matrix/esps"         
        payload: '{"state":"ON"}'
                                                                   
- alias: EspixelStick110 Off                                                         
  trigger:                                                                                  
    - platform: state                                                                       
      entity_id: binary_sensor.isdark                                                       
      to: 'off'                                                                             
  condition:                                                                                
    - condition: state                                                                      
      entity_id: binary_sensor.isdark
      state: 'on'                                                                           
  action:                                                                                   
    - service: mqtt.publish                                                                 
      data_template:                                                                        
        topic: "matrix/esps"                                               
        payload: '{"state":"OFF"}'                         
script: !include scripts.yaml

Can you format your code using the mark up tools please? (the <> icon in the editor)
first thing I noticed is you have a couple of automations that use binary_sensor.isdark as a trigger and as a condition.
If you trigger on binary_sensor.isdark changing to on you don’t need to add a condition that binary_sensor.isdark = on.
Also your second automation will never run as it triggers on binary_sensor.isdark = off but your condition is binary_sensor.isdark = on
you also have a weird script: !include scripts.yaml in your automation?

Thank you for the reply. I am still learning a lot of this and have been hacking pieces together and seeing what sticks.
The weird script: !include scripts.yaml in my automation is just an over copy of my config.yaml.

So I don’t need to add a condition to my Automation?

#espixelstick subnet 110
  - platform: mqtt
    name: "PixelStick01"
    state_topic: "matrix/esps/light/status"
    command_topic: "matrix/esps/light/switch"
    brightness_state_topic: "matrix/esps/brightness/status"
    brightness_command_topic: "matrix/esps/brightness/set"
    rgb_state_topic: "matrix/esps/rgb/status"
    rgb_command_topic: "matrix/esps/rgb/set"
    brightness: true
    flash: true
    rgb: true
    optimistic: false
    qos: 0
	
	sensor:
#Light sensor
  - platform: mqtt  
    state_topic: "bruh/sensornode1"  
    name: "SN1 LDR"
    ##This sensor is not calibrated to actual LUX. Rather, this a map of the input voltage ranging from 0 - 1023.
    unit_of_measurement: "LUX"  
    value_template: '{{ value_json.ldr }}'  
    
# Binary Sensors
binary_sensor:
  - platform: threshold
    name: isdark
    entity_id: sensor.sn1_ldr
    lower: 100
    hidden: true
	
#Groups
group:  
  sensor_node_1_card:  
    name: Sensor Node 1  
    entities:  
      - sensor.sn1_temperature  
      - sensor.sn1_humidity  
      - sensor.sn1_ldr  
      - light.sn1_led
	
automation:
- alias: EspixelStick110 On       
  trigger:                               
    - platform: state                    
      entity_id: binary_sensor.isdark    
      to: 'on'                           
    action:                                
    - service: mqtt.publish              
      data_template:                     
        topic: "matrix/esps"         
        payload: '{"state":"ON"}'

- alias: EspixelStick110 Off                                                         
  trigger:                                                                                  
    - platform: state                                                                       
      entity_id: binary_sensor.isdark                                                       
      to: 'off'                                                                             
    action:                                                                                   
    - service: mqtt.publish                                                                 
      data_template:                                                                        
        topic: "matrix/esps"                                               
        payload: '{"state":"OFF"}'

So I was digging around and noticed the “The service dev tool” in Hassio and was able to come up with a working automation.
Now I need to be able to figure out how to send a color, and possibly send different colors based on different environmental variables.

- alias: EspixelStick110 On       
  trigger:                               
    - platform: state                    
      entity_id: binary_sensor.isdark    
      to: 'on'                           
  action:                                
    - service: homeassistant.turn_on                                                                
      entity_id: 
        light.pixelstick110                                                                        

                                                                   
- alias: EspixelStick110 Off                                                         
  trigger:                                                                                  
    - platform: state                                                                       
      entity_id: binary_sensor.isdark                                                       
      to: 'off'                                                                             
  action:                                                                                   
    - service: homeassistant.turn_off                                                                
      entity_id: 
        light.pixelstick110

great.
For the colours, here is an example:

  - service: light.turn_on
    data:
      entity_id: light.pixelstick110
      brightness: 255
      rgb_color: [0,255,0]
      transition: 1
1 Like

Thank again but no go
Invalid config for [automation]: expected dict for dictionary value @ data[‘action’][0][‘data’]. Got None
extra keys not allowed @ data[‘action’][0][‘brightness’]. Got None
extra keys not allowed @ data[‘action’][0][‘rgb_color’]. Got None
extra keys not allowed @ data[‘action’][0][‘transition’]. Got None. (See /config/configuration.yaml, line 187). Please check the docs at Automation - Home Assistant

Can you share your automation?

Here is the erred automation looked like

- alias: EspixelStick110 On       
  trigger:                               
    - platform: state                    
      entity_id: binary_sensor.isdark    
      to: 'on'                           
  action:                                
    - service: homeassistant.turn_on                                                                
      data:
      entity_id: light.pixelstick110
      brightness: 255
      rgb_color: [0,255,0]
      transition: 1

You’re missing the indentation after data: :wink:

1 Like

Let me try again

We have Lime!
Totally working.

1 Like