Newbie. How can I know if a device is on or off?

Hi, I’m using HASS to control the fan coils in my house. The automation scheduling works well in terms of timings and temperatures, but I need to set up an automation that checks whether the devices are on or off.

Does anyone know where I can find YAML code to do this?
I’ve tried everything, but I always get an ERROR

Regards

How are you controlling them? Shelly? DIY Contactor control?

Condition: If Device off/on turn on/off

Would be easier to understand what you mean/want, if you post your automation, choose Yaml, copy it, paste it here using the </>

You can only ever know whether Home Assistant thinks they are on or off. :grinning_face_with_smiling_eyes:

Thank you for your replies.
Below is the kitchen automation system.
This is running on HACS, with Innova devices.

Between 7:30 and 8:00, it repeats commands to switch on the fan coil.
It then raises the temperature according to the room sensor.
I copied all this from people who posted it online, and it usually works. I’m not entirely sure if it’s done properly, or if it’s a bit of a botched job.

My question is this: sometimes the fan coil’s Wi-Fi fails, and they’re disconnected from Home Assistant for a while; if that happens just as they’re due to switch on, the fan coil stays off until I check it.

That’s why I’d like to set up an automation that checks every hour whether the devices are off; if they are, it would send a command to switch them on.
The same applies at night, checking if any are still running, to send a command to switch them off.

Regards

alias: Cocina
description: "260405"
triggers:

  • trigger: time_pattern
    minutes: /10
    conditions:
  • condition: time
    after: "07:30"
    actions:
  • choose:

Encendido

- conditions:
  - condition: time
    before: "08:00"
  sequence:
    - target:
        entity_id: climate.cocina
      action: climate.turn_on
    - target:
        entity_id: climate.cocina
      action: climate.set_fan_mode
      data: 
        fan_mode: auto

desde las 08:00 a las 08:40

- conditions:
    - condition: time
      after: "08:00"
      before: "08:40"
    - condition: numeric_state
      entity_id: sensor.cocina_aire
      below: 18
  sequence:
    - target:
        entity_id:
          - climate.cocina
      data:
        temperature: "{{ states('sensor.v_cocina_2') }}"  # +1,5º
      action: climate.set_temperature
- conditions:
    - condition: time
      after: "08:00"
      before: "08:40"
    - condition: numeric_state
      entity_id: sensor.cocina_aire
      above: 17.9
  sequence:
    - target:
        entity_id:
          - climate.cocina
      data:
        temperature: 20
      action: climate.set_temperature

desde las 08:40 a las 19:00

- conditions:
    - condition: time
      after: "08:40"
      before: "19:00"
    - condition: numeric_state
      entity_id: sensor.cocina_aire
      below: 20.8
  sequence:
    - target:
        entity_id:
          - climate.cocina
      data:
        temperature: "{{ states('sensor.v_cocina_1') }}"  # +1,2º
      action: climate.set_temperature
- conditions:
    - condition: time
      after: "08:40"
      before: "19:00"
    - condition: numeric_state
      entity_id: sensor.cocina_aire
      above: 20.7
  sequence:
    - target:
        entity_id:
          - climate.cocina
      data:
        temperature: 22
      action: climate.set_temperature

desde las 19:00 a las 21:30

- conditions:
    - condition: time
      after: "19:00"
      before: "21:30"
    - condition: numeric_state
      entity_id: sensor.cocina_aire
      below: 21.9
  sequence:
    - target:
        entity_id:
          - climate.cocina
      data:
        temperature: "{{ states('sensor.v_cocina_1') }}"  # +1,2º
      action: climate.set_temperature
- conditions:
    - condition: time
      after: "19:00"
      before: "21:30"
    - condition: numeric_state
      entity_id: sensor.cocina_aire
      above: 21.8
  sequence:
    - target:
        entity_id:
          - climate.cocina
      data:
        temperature: 23
      action: climate.set_temperature

desde las 21:00 a las 23:00

- conditions:
    - condition: time
      after: "21:30"
      before: "23:00"
    - condition: numeric_state
      entity_id: sensor.cocina_aire
      below: 20.9
  sequence:
    - target:
        entity_id:
          - climate.cocina
      data:
        temperature: "{{ states('sensor.v_cocina_1') }}"  # +1,2º
      action: climate.set_temperature
- conditions:
    - condition: time
      after: "21:30"
      before: "23:00"
    - condition: numeric_state
      entity_id: sensor.cocina_aire
      above: 20.8
  sequence:
    - target:
        entity_id:
          - climate.cocina
      data:
        temperature: 22
      action: climate.set_temperature

Apagado entre semana

- conditions:
  - condition: time
    after: "23:00"
    weekday:
      - mon
      - tue
      - wed
      - thu
      - fri
      - sun
  sequence:
    - target:
        entity_id: climate.cocina
      action: climate.set_temperature
      data:
        temperature: 16
    - target:
        entity_id: climate.cocina
      action: climate.turn_off

- conditions:
  - condition: time
    after: "23:45"
    weekday:
      - sat
  sequence:
    - target:
        entity_id: climate.cocina
      action: climate.set_temperature
      data:
        temperature: 16
    - target:
        entity_id: climate.cocina
      action: climate.turn_off

mode: queued

How do you know if the light of the refrigerator is off...
There is a joke: open the refrigerator, empty it, go sit in it, close the door.
Sorry, I couldn't resist. :innocent:

If you setup the system correctly you have to trust HA but of course if you use wireless devices, the availability depends on the wireless network.
WiFi can seem to be the obvious way since that's probably almost always present before any other wireless technology.
There are quite some users here that rely completely on WiFi with HA and their systems run stable.

I started with a few WiFi devices but switched quite immediately to zigbee to not rely on my WiFi network and stress it not more.

1 Like

Which entity in your automation represents the "fan coils"?

Is it climate.cocina?

What is the name of the integration that produces climate.cocina?

What is the name of the integration that produces sensor.cocina_aire?

I'm unclear on your automation. It looks like you are checking every 10 minutes what time it is and then adjusting the thermostat (climate.cocina) up or down based on what the temperature is.

A climate entity should maintain the temperature for you automatically. Does your climate entity not do that? That might be the first thing to look at.

Instead of triggering every ten minutes and then testing what time it is, what about just triggering when you want to change the thermostat's set point and set it to what you want. That's how thermostats with schedules typically work.

See also:

It sounds a little strange, but it actually works well.
At least with the fan coils I have.

If the set temperature is much higher than the room temperature, it blows really hard and makes quite a bit of noise.
What I do is set it every 10 minutes to the room temperature plus 1°C or 1.5°C; that way, they’re quieter, and I end up getting the desired temperature anyway.

The integration is Innova; it is loaded via HACS.
The example I gave is just one of them. There are 11 others.
sensor.cocina.aire is the ambient temperature measured by a fan coil sensor

Thank you for your interest; what I'm interested in is being able to check the status of the fan coils and take appropriate action.

I've seen it before, using “state” or “states,” but now I can't find it.

So you are trying to warm up the room slowly so the fan stays quiet, correct? You are trying to essentially build your own cut-off system when it gets too hot, i.e. micromanage the heater. Interesting. How do you know that the heater won't get too hot in the 10 minute window and turn on high/loud anyway?

The fan going faster/louder is probably a safety feature when the heater gets too hot, and kind of seems like a separate issue from setting the temp, but I'm sidetracking...

First thing is to see what HA can give you to trigger on. Your goal is to know it got turned on, right?

When you turn it on you can use a wait_template to see that the state really changed. But, make sure to use a timeout.

That said, what defines it being on? The switch reports that it's on or off? Or that it's actually heating (e.g. a smart switch is reporting the switch drawing current) or the temp is actually rising?

What happens in Home Assistant if you power off the fan coil -- that is what happens in HA if its wifi is powered off? Is there a state change you can trigger on? Obviously, if you are running a heater via a wifi switch you want to make sure the wifi is stable first. That's a safety issue.


Again, personally I feel like this is two (or more) separate issues.

I'd simplify the setting of the temps at different times of the day. Set the temp you want and let the climate integration handle maintaining that temp.

And then handle the fan separately, which might mean monitoring the temp in the fan and pausing when it gets too hot where the fan might turn on. Is there not a lower wattage setting that wouldn't trigger the fan?

Something like this to set the temp
triggers:
  - trigger: time
    at: "07:00:00"
    id: "68"
  - trigger: time
    at: "08:00:00"
    id: "68"
  - trigger: time
    at: "09:30:00"
    id: "60"
  - trigger: time
    at: "21:30:00"
    id: "72"
  - trigger: time
    at: "23:00:00"
    id: "62"
    weekday:
      - sun
      - mon
      - tue
      - wed
      - thu
      - fri
  - alias: Party Day
    trigger: time
    at: "23:45:00"
    id: "62"
    weekday:
      - sat
actions:
  - action: climate.set_temperature
    metadata: {}
    target:
      entity_id: climate.primary_bath
    data:
      temperature: "{{ trigger.id }}"

I have separate automations that monitor that the temp sensors are available and have recently been updated, for example.

See that link about in the Script docs as it has lots of examples.

OK, so it’s responsible for creating climate.cocina and sensor.cocina_aire.

When this happens, does the state value of sensor.cocina_aire, and/or climate.cocina, change to unavailable?

When an integration loses contact with the entities it controls, it's normal for it to report it as an unavailable state.

If the Innova integration doesn't do this then you have no way of knowing when the entities are not communicating properly.

I use a template binary sensor to let me know if my wood stove fan is running. While the outlet for the wood stove is automated, if the stove also has an element that only lets the fan run when it's hot.d. This tells me whether the fan is actually running ( drawing power ).

{{ states('sensor.woodstove_outlet_power')|int() > 0.2 }}

Is that the sort of thing you seek?

I can think of two ways, though it involves a third device, an ESP-01, breakout board and power supply USD$15.

In either case, the device sends a heartbeat that is monitored by a watchdog automation.

  1. flap that closes micro switch.
  2. Current transformer on one of the leads to the fan coils.

That’s correct; when Wi-Fi connectivity is lost, the associated devices and sensors disappear.

If the automation system attempts to switch on a device for 15 minutes and there is no Wi-Fi during that time, the device remains switched off.

What I’m looking to do is automate subsequent attempts to switch it on once the connection has been restored.

Well, I could also do it the hard way, by sending power-on commands to all devices every hour, for example, but that doesn’t seem like a very scientific method to me.

Disappear when Wi-Fi connectivity is lost?

Do you mean the entities sensor.cocina_aire and climate.cocina cease to exist in Home Assistant? Or they continue to exist but their reported values are unavailable?

For example, I have a smart plug (switch.library_plug) that is not currently plugged in (so it is not connected to Wi-Fi). The entity exists in Home Assistant but its state value is unavailable.

That's possible, provided the entities don't "disappear" when they're not connected via Wi-Fi and their state is reported as unavailable. That's why I have been attempting to clarify these details.

Since this is running something important (and is a potential safety issue) fixing the wifi should be top priority. You really want to be able to control it when you want to.[1]

HA works based on events, so think in those terms. One idea: I might do something like use a template sensor and turn that on and off -- and then have the physical switch trigger off of that change. That way you have a local state variable that tells you what should be the current state. (Things get simpler when you focus on state changes only.)

Then have an automation that triggers on the wifi devices state -- when it changes from unavailable you can then set it on or off based what's its current state is supposed to be.

You can also run that automation when HA restarts.

Is it possible to separate out the thermostat temp set point, the wifi issues, and the fan noise into separate problems to solve?

[1] For critical devices I use switches that have an auto-off timer built in so if HA vanishes or the network switch explodes the device will have a fail-safe power off at some time.

The noise the fans make when running isn’t a problem; I solved it by gradually increasing the set temperature, and that works well.

As for the Wi-Fi issues, the Wi-Fi modules installed in these devices aren’t very reliable; there are often connectivity drops, although these are usually very brief. Sometimes the problem lasts longer and I have to reset them to get them working again.

As for monitoring changes in the devices’ status and then taking action, I don’t know how to do that.

That’s why I’m asking these questions.

Regards

I can help you with that but I require answers to the questions in my previous post.

1 Like