Service switch is missing?

Hi there!

I have HA v0.111.4 and it seems that Service Switch is missing under developer tools. Also calling REST API with working token /api/services/switch/turn_on returns 400: Bad Request

Have I missed some important change or has the switch really been disabled? How do the automations work now as I cannot call switch?

Check your log for errors, perhaps an invalid switch configuration is preventing the switch platform from being set up. I’m on the same version and can see the services:

switch

Yeah, thanks for pointing that out. It that seems to be it.

I guess I had the whole switch: removed from configuration so it did not initialize that at all in HA.

I was going to suggest checking if you had switch: in your configuration.yaml file but assumed you did as it sounded like you previously had working switches. So I went with the probable cause being an invalid config instead.

I was toggling around with enhanced I2C polling scripts.

But still something is off as automations are not actiwating switches when sensor state is changed.

They worked earlier just fine, but now they can only be activated when I push EXECUTE button on HA UI or directly enable the switch. Changing the sensor state via physical button or API does not trigger the automation.

Any ideas if the automation ‘encoding’ has changed, i.e. how the automation is defined? Could it be that the platform state to ON is missing the sensor state change in more recent HA version?

The sensor state has been changed:
image

This worked previously:

- id: '201708130001'
  alias: 'WC light'
  trigger:
  - entity_id: sensor.i2c_tek_pin_in_01
    platform: state
    to: 'on'
  action:
  - entity_id: switch.i2c_tek_pin_out_01
    service: switch.toggle

No recent changes to automations that I’m aware of.

Look in the developer tools states menu and make sure your automation is enabled (‘on’).

If the automation is off, you can include this to ensure it does not happen again:

- id: '201708130001'
  alias: 'WC light'
  initial_state: true # <------ This here
  trigger:
...etc

There have been reports of all automations occasionally being disabled after a restart even though this is not supposed to be the default behaviour: https://www.home-assistant.io/docs/automation#automation-initial-state

Thanks. I’ll add this and see what happens.

Hmm… initial-state did not have any effect.

Your i2c sensor is not a binary sensor. It is reporting STATE_OFF not 'off' as a binary sensor would. I assume the same will be true for on.

Try:

  trigger:
  - entity_id: sensor.i2c_tek_pin_in_01
    platform: state
    to: 'STATE_ON'

Or change your sensor definition to a binary sensor.

Sweet! Using STATE_ON instead of on fixed the problem on triggers. Thanks!

1 Like