On_value to not execute when WIFI disconnects

Hi There,

I have a sensor which is supposed to be updated each time a homeassistant input_number is updated.
The problem is that this sensor gets also updated when the WIFI disconnects and then reconnect.
So I would like to implement a conditional on_value for this sensor.
I have created a status sensor and a previous_status sensor. The code of the sensor goes like this:

binary_sensor:
  - platform: status
    name: Status_${reference}
    id: internal_status_${reference}
  - platform: status
    name: previous_status_${reference}
    id: previous_internal_status_${reference}
    internal: true

Then an interval each second:

interval:
  - interval: 1s
    then:
      if:
        condition:
          wifi.connected:
        then:
          - lambda: |-
              id(previous_internal_status_${reference}).publish_state( id(internal_status_${reference}).state  );
              id(internal_status_${reference}).publish_state(true); 
              
        else:
          - lambda: |-
              id(internal_status_${reference}).publish_state(false);

Then in the sensors:

  - platform: homeassistant
    name: "somfy_position_to_reset"
    entity_id: input_number.somfy_manual_logicalreset_to_position
    on_value:
      then:
        - if:
            condition: 
              and:
                - binary_sensor.is_off: previous_status_${reference}
                - binary_sensor.is_on:  status_${reference}
                
            then:
              - lambda: |-
#                 Consume the false previous status
                  id(previous_status_${reference}).publish_state(true);
#                 Then run action
                  id(somfy_cover).position= x/100 ;
                  id(somfy_cover).publish_state() ; 

But the code doesnt compile, the error is saying "while parsing a block mapping (poimting on the lamdda line of the on_value action), expected <block_end> but found .
I have spent a lot of time looking for the syntax error, but couldnt find it.
Does anyone have an idea? Would be greatly appreciated.
or is there another way to achieve the same goal (of having a on_value NOT executed when the system reconnects to WIFI)?

Many thanks, Felix

Isn’t the comment code in lambdas // not #

1 Like

Congratulations… believe it or not, it took me a while yesterday (several hours), before I gave up and wrote. This was it precisely. Many thanks Nick!!

1 Like