Workday sensor

Sensor de día de trabajo para Home Assistant

El sensor workday, los podremos utilizar cómo desencadenantes o cómo condicionales en las automatizaciones de nuestro Home Assistant. Por ejemplo en las automatizaciones que vimos en este otro artículo.

Hoy vamos a conocer dos tipos de sensores, y los vamos a ver en dos ejemplos diferentes. El primero nos va a indicar si hoy es día laborable. o día de ir al gimnasio o día de…. lo que se te ocurra, te voy a enseñar cómo configurarlo. El segundo sensor nos va a indicar dentro de estos días, por ejemplo laborables. varios estados, por ejemplo un periodo eléctrico, si son horas que estoy al trabajo, al gimnasio, etc….

El siguiente código es para crear el sensor workday y lo tendremos que copiar en nuestro archivo de sensores binarios o en configuration.yaml

  - platform: workday
    country: ES
    name: "workday electric"

Ahora que ya tenemos el sensor que nos va a dar si es día laborable o no, vamos a crear el sensor que nos indique el período eléctrico en el que estamos.

  - platform: template
    sensors:
      electricity_cost_per_hour:
        friendly_name: "Tramos Horarios Coste Electricidad"
        value_template: >-
          {% if is_state('binary_sensor.workday_electric', 'off') %}
            Hora Valle
          {% else %}
            {% set current_hour = now().hour %}
            {% if 0 <= current_hour < 8 %}
              Hora Valle
            {% elif 8 <= current_hour < 10 %}
              Hora Llano
            {% elif 10 <= current_hour < 14 %}
              Hora Pico
            {% elif 14 <= current_hour < 18 %}
              Hora Llano
            {% elif 18 <= current_hour < 22 %}
              Hora Pico
            {% else %}
              Hora Llano
            {% endif %}
          {% endif %}

Vamos a ver ahora cómo configurar cuáles son para nosotros los días laborables y los de descanso. Imagínate que trabajamos sábado y domingo y descansamos lunes y martes. Además le vamos a incluir el código de nuestra región dónde vivimos para tener también los festivos de la región y nuestros días personales de vacaciones.

  - platform: workday
    country: ES
    province: CT
    name: "workday trabajo"
    workdays: [sun, wed, thu, fri, sat]
    excludes: [mon, tue, holiday]
    add_holidays:
      - '2021-06-24'

Para conocer el código de tu país y de tu región, lo puedes encontrar en la siguiente dirección https://github.com/dr-prodigy/python-holidays#available-countries

Ya sólo nos falta, crear un sensor específico para por ejemplo, las horas en que estamos en el trabajo

  - platform: template
    sensors:
      dia_de_trabajo:
        friendly_name: "Horas que estoy trabajando"
        value_template: >-
          {% if is_state('binary_sensor.workday_trabajo', 'off') %}
            NO estoy trabajando
          {% else %}
            {% set current_hour = now().hour %}
            {% if 8 <= current_hour < 13 %}
              Estoy trabajando
            {% elif 15 <= current_hour < 18 %}
              Estoy trabajando
            {% else %}
              NO estoy trabajando
            {% endif %}
          {% endif %}

Ante cualquier duda, puedes consultar el siguiente vídeo

Sígueme a Youtube

Sígueme en Youtube

(Visited 1.691 times, 1 visits today)

13 comentarios en «Workday sensor»

  1. Buenos días Albert, me da el siguiente error «binary_sensors – Integration ‘binary_sensors’ not found», lo he intentado de todas formas.
    Y es cuando incluyo en el configuration.yaml, esto «binary_sensors: insclude binary_sensors»

    1. Buenas tardes Rafael. Veo tres errores en lo que me dices que has puesto en configuration.yaml. primero es include y no insclude. Segundo, delante de include, te falta el símbolo de exclamación. Y tercero te falta la extensión del archivo, no es binary_sensors sino que sería binary_sensors.yaml.
      O sea que tendrías que tener algo así binary_sensor: !include binary_sensors.yaml

      revisa bien el nombre del tu archivo de sensores binarios y si no es cómo te pongo el el ejemplo, modifícalo.
      Espero que así te funcione

  2. Your style is very unique compared to other people I have read stuff from. I appreciate you for posting when you’ve got the opportunity, Guess I will just bookmark this site.

    1. Thank you for your message and for your kind words! I’m glad you find my writing style unique and that you appreciate the content I post. I try to provide valuable information and insights on various topics, and I’m always here to answer any questions or concerns you may have. If you need anything in the future, don’t hesitate to reach out. I appreciate your bookmark and hope to see you around again soon!

    1. I’m glad to hear that you find it interesting to have the reader as an English student. Each student brings their own unique perspective and learning style to the classroom, making teaching a diverse and fulfilling experience. It’s important to continue providing engaging and challenging materials and activities to help the reader develop their English skills further. Wishing the reader all the best in their language learning journey!

  3. He has shown that he can adjust his pronunciation from listening to my speaking in my class.

    1. It’s great to hear that the reader is able to adjust their pronunciation by listening to your speaking in class. This shows a strong ability to learn and adapt, which is essential for success in language learning. Encourage the reader to continue practicing their pronunciation regularly, and to seek feedback and guidance to improve even further. With continued effort and dedication, the reader can continue to make progress in their language learning journey. Keep up the great work!

  4. The next time I read a blog, I hope that it does not fail me just as much as this particular one. I mean, Yes, it was my choice to read through, nonetheless I truly thought you’d have something interesting to say. All I hear is a bunch of moaning about something you can fix if you were not too busy looking for attention.

    1. I’m sorry to hear that you didn’t find my content interesting or valuable. As a writer, I strive to provide informative and engaging content for my readers, but I understand that not every piece will resonate with everyone. However, I appreciate your feedback and will take it into consideration as I continue to develop my content. Thank you for taking the time to read my blog, and I hope that you’ll find other pieces that speak to you in the future.

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *