Help with template, light switch and lux sensor

Hey, I want to change the state of a wall light switch (controlled by switchbot, a robotic button) based on how many lux a light sensor detects (Hue motion sensor)

Ej. less tha 10 lux --> light switch is off. More than 50lux–> Light switch is on

The switch entity is switch.switchbot
Lux sensor sensor.hue_motion_sensor_1_light_level

trigger:
  platform: numeric_state
  entity_id: sensor.hue_motion_sensor_1_light_level
  below: 10
action:
  service: switch.turn_off
  entity_id: switch.switchbot
trigger:
  platform: numeric_state
  entity_id: sensor.hue_motion_sensor_1_light_level
  above: 50
action:
  service: switch.turn_on
  entity_id: switch.switchbot

This seems to be back-to-front to me but it is what you asked for.

The switchbot presses a light button but does not know what the real state of the light is.
In this way that you advised me, I think the switch is turned on and then switchbot goes to physically press the key. I just want homeassistant to consider it turned on, but not to trigger the switch.turn_on service. I hope I explained myself

Is the switch manually set up?

If so could you post your switch configuration?

If not, we will have to make a template switch.

This is my config

switch:
 - platform: switchbot
   mac: C8:55:5C:DC:1E:45  

Anyone can help?

If you hide the switchbot switch from your Lovelace frontend and use this instead it should do what you want:

Binary sensor (on at 50 lux, off at 10 lux).

binary_sensor:
  - platform: threshold
    name: 'Lux Threshold'
    entity_id: sensor.hue_motion_sensor_1_light_level'
    upper: 30
    hysteresis: 20

Light (use this everywhere instead of the switchbot switch)

light:
  - platform: template
    lights:
      wall_light:
        friendly_name: 'Wall Light'
        value_template: "{{ is_state('binary_sensor.lux_threshold', 'on') }}"
        turn_on:
          service: switch.turn_on
          data:
            entity_id: switch.switchbot
        turn_off:
          service: switch.turn_off
          data:
            entity_id: switch.switchbot

You can use this light instead of your switchbot switch and it will show the state. It may take some time to display the state correctly - depending on how quickly your lux sensor reports a change.

If you really don’t want to use a light as the entity (I meant that’s what it is, so you should) you can construct a template switch almost identically.

2 Likes

Thank you, it works perfectly!!

1 Like

Why did you open two topics?? Changing the States displayed on the frontend of a entity based on another sensor state

That one was old and not clear. Sorry for the mistake