Loosing my mind. Esphome, deep sleep and Mqtt won't work together

I recently had a project where I used deep sleep. Intention was to have the device sleep whilst i was asleep and awake when I woke up. The method was successful but my battery setup still not sufficiently sized so abandoned the idea. Perhaps useful for others though. Source: https://tatham.blog/2021/02/06/esphome-batteries-deep-sleep-and-over-the-air-updates/

I used ha booleans and input numbers to control the prevent and duration respectively. No reliance on mqqt as the API functionality was sufficient for me. Please double check indentation when using this. I copied it from plain text.

deep_sleep:
  id: deep_sleep_control
  sleep_duration: 1min
  
binary_sensor:
  - platform: homeassistant
    id: prevent_deep_sleep
    name: Prevent Deep Sleep
    entity_id: input_boolean.prevent_deep_sleep
    
script:
  - id: consider_deep_sleep
    mode: queued
    then:
      - delay: 30s
      - if:
          condition:
            binary_sensor.is_on: prevent_deep_sleep
          then:
            - logger.log: 'Skipping sleep'
          else:
            - logger.log: "Time to sleep !!! Hibernating"
            - lambda: |-
                id(deep_sleep_control).set_sleep_duration(id(deep_sleep_duration).state);
            - delay: 1s
            - deep_sleep.enter: deep_sleep_control
      - script.execute: consider_deep_sleep
      
sensor:
  - platform: homeassistant
    id: deep_sleep_duration
    name: Deep Sleep Duration
    entity_id: input_number.deepsleep_duration