Light entity will not be update after toggling switch

I’m trying to configure Sonoff mini switch to toggle our bedroom lights.
So far I have create a switch for it and I can toggle the lights on and off (if the entity is updated). But I want to force update the entity to automatically get the newest state of the switch.

So is there a way to force updating the state of the entity because my switch is relaying on that entity state? Below is my configuration of the switch and the entity that I refer to is a rest sensor.

switch:
  - platform: template
    switches:
      masterbedroom:
        value_template: "{{ is_state('sensor.licht_master_bedroom', 'on') }}"
        turn_on:
          service: rest_command.master_bedroom_on
          entity_id: sensor.licht_master_bedroom
        turn_off:
          service: rest_command.master_bedroom_off
          entity_id:  sensor.licht_master_bedroom

rest_command:
  master_bedroom_off:
    url: "http://192.168.0.201:8081/zeroconf/switch"
    method: post
    payload: '{ "deviceid": "100000140e", "data": { "switch": "off" }}'
  master_bedroom_on:
    url: "http://192.168.0.201:8081/zeroconf/switch"
    method: post
    payload: '{ "deviceid": "100000140e", "data": { "switch": "on" }}'

Added a new service for updating the state of the entity:

          - service: homeassistant.update_entity
            entity_id: sensor.licht_master_bedroom

Assuming there is a rest endpoint to read the state of the Sonoff switch, you can use a Restfull switch RESTful Switch - Home Assistant

It allows you to define both how to switch on/off the switch, and to read its status.

I tried first but for reading the state on the Sonoff switch there need to be a body in the request. And did not found any way to include a body to the request.

Too bad :frowning:

You could still use a Rest sensor RESTful Sensor - Home Assistant (home-assistant.io) to read the state, then an automation on it to position the switch…