Hassio REST switch - rest

I'm trying to make Home Assistant button/switch, which changes state of my lamp through REST call.
I got set up server with command, which changes state of lamp on 192.168.43.21/lampSwitch and returns json {"state": "ON"} or OFF, based on after-switching state.
I'm facing problem with scripting entities and showing current/returned state in Hassio - acquiring state and changing it via home-screen switch.
My configuration:
# Loads default set of integrations. Do not remove.
default_config:
# Text to speech
tts:
- platform: google_translate
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
rest:
- scan_interval: 5
resource: http://192.168.43.21/
sensor:
- name: "Temperatura"
# unique_id: "sensor.temperature_sensor"
json_attributes_path: "$.response.system"
value_template: "{{value_json['temperature']}}"
json_attributes:
- "temperature"
- name: "Wilgotność powietrza"
# unique_id: "sensor.humidity_sensor"
json_attributes_path: "$.response.system"
value_template: "{{value_json['humidity']}}"
json_attributes:
- "humidity"
- name: "Poziom wody"
# unique_id: "sensor.water_sensor"
json_attributes_path: "$.response.system"
value_template: "{{value_json['water']}}"
json_attributes:
- "water"
lamp_switch:
- command: "Lamp switch"
trigger:
platform:
action:
url: http://192.168.43.21/lampSwitch/
I saw solution which uses cURL and command line, but I couldn't find any suiting example.
Note that the rest entities works just fine (shows up at home screen).
Thank you in advance

I use this to launch applications on my Samsung TV. I define my_command in Configuration.yaml, then use:
/bin/bash -c "/usr/bin/curl -X POST 'http://<<My_IP>>:8001/api/v2/applications/'{{ variables.my_command }}"
I call this from a button and pass a variable that defines the application that I want.
I hope this helps.

Related

VSCode-Docker Not Invoking "CMD"

TL;DR Image built by VSCode only executes the CMD command when I press the Run button in the Docker Desktop UI.
Hello Folks,
I'm playing around with a Drools image along with Docker Desktop and VSCode.
My devcontainer.json file looks like the following:
{
"name": "Existing Dockerfile",
"build": {
// Sets the run context to one level up instead of the .devcontainer folder.
"context": "..",
// Update the 'dockerFile' property if you aren't using the standard 'Dockerfile' filename.
"dockerfile": "../Dockerfile"
},
// Use 'forwardPorts' to make a list of ports inside the container available locally.
"forwardPorts": [8001,8080]
}
My Dockerfile is minimalist and looks like the following:
FROM quay.io/kiegroup/business-central-workbench:latest
And my compose.yaml file looks like so:
services:
app:
entrypoint:
- sleep
- infinity
image: docker/dev-environments-default:stable-1
init: true
volumes:
- type: bind
source: /var/run/docker.sock
target: /var/run/docker.sock
The issue is that when VSCode sends the image to Docker Desktop, the
CMD ["./start_business-central-wb.sh"] found in the parent image does not seem to be getting set off as seen in the logs
However, when I click "Run" the command gets kicked off after spawning a new instance
What concept am I missing as to why the Docker image doesn't immediately begin running when VSCode sends it to Docker Desktop? I'm super inexperienced with both techs.
Any help is greatly appreciated.

DevSpace hook for running tests in container after an update to the container

My ultimate goal is to have tests run automatically anytime a container is updated. For example, if update /api, it should sync the changes between local and the container. After that it should automatically run the tests... ultimately.
I'm starting out with Hello World! though per the example:
# DevSpace --version = 5.16.0
version: v1beta11
...
hooks:
- command: |
echo Hello World!
container:
imageSelector: ${APP-NAME}/${API-DEV}
events: ["after:initialSync:${API}"]
...
I've tried all of the following and don't get the desired behavior:
stop:sync:${API}
restart:sync:${name}
after:initialSync:${API}
devCommand:after:sync
At best I can just get Hello World! to print on the initial run of devspace dev -b, but nothing after I make changes to the files for /api which causes files to sync.
Suggestions?
You will need a post-sync hook for this, which is separate from the DevSpace lifecycle hooks. You can define it with the dev.sync directly and it looks like this:
dev:
sync:
- imageSelector: john/devbackend
onUpload:
execRemote:
onBatch:
command: bash
args:
- -c
- "echo 'Hello World!' && other commands..."
More information in the docs: https://devspace.sh/cli/docs/configuration/development/file-synchronization#onupload

Issues in making a .sh script run on each boot with cloud-init

I supply the below cloud-init script through Azure portal in creating a VM. and the script never runs. appreciate if anyone can suggest what's wrong with my #cloud-config upload.
observation -
ubuntuVMexscript.sh is written
test.sh is NOT written in home directory
/etc/cloud/cloud.cfg doesn't show the change of [scripts-user, always] in final modules.
#cloud-config
package_upgrade: true
write_files:
- owner: afshan:afshan
path: /var/lib/cloud/scripts/per-boot/ubuntuVMexscript.sh
permissions: '0755'
content: |
#!/bin/sh
cat > testCat < /var/lib/cloud/scripts/per-boot/ubuntuVMexscript.sh
- owner: afshan:afshan
path: /home/afshan/test.sh
permissions: '0755'
content: |
#!/bin/sh
echo "test"
cloud_final_modules:
- rightscale_userdata
- scripts-vendor
- scripts-per-once
- scripts-per-boot
- scripts-per-instance
- [scripts-user, always]
- ssh-authkey-fingerprints
- keys-to-console
- phone-home
- final-message
- power-state-change
write_files runs before any user/group creation. Does the afshan user exist when write_files is being run? If not, attempting to set the own on the first file will throw an exception, and the write_files module will exit before attempting to create the second file. You can see if this is happening by checking /var/log/cloud-init.log on your instance.
/etc/cloud/cloud.cfg won't get updated by user data. It will stay as-is on disk, but your user data changes will get merged on top of it.
scripts-user refers to scripts written to /var/lib/cloud/instance/scripts. You haven't written anything there, so I'm not sure the purpose of your [scripts-user, always] change. If you're just looking to run a script every boot, the scripts-per-boot module (without any changes) should be fine. Every boot, it will run what's written to /var/lib/cloud/scripts/per-boot

Ansible IP Adress from Host to Variable and use in Playbook - Save Switch Config with Ansible

I want to save the startup and running config with ansible. My script works but only on one host. I need to change the name from the save file otherwise it will overwrite the old Configuration.
---
- hosts: switches
gather_facts: yes
vars:
ansible_network_os: icx
ansible_become: True
ansible_become_method: enable
tasks:
- name: Backup Config Files
icx_command:
commands:
- copy startup-config tftp 192.168.10.5 Ansible-startup-config.cfg
- copy running-config tftp 192.168.10.5 Ansible-running-config.cfg
Now I want to have the ip address, time and date in the name so that they will not be overwritten when I start the script again.
I think about something like this as filename:
192.168.9.13-2021-04-08-18:25-startup-config.cfg
or an consecutive number
How can I do this?
The rough idea below.
I'm not 100% sure facts gathered on ios populate ansible_default_ipv4. You will have to check that point and find the correct variable if needed. Note also you may have to run explicitly the icx_facts module to get all the info from your device.
You can run the following ad-hoc commands to browse all available facts and choose the correct one if ever:
ansible -i your_inventory some_host -m setup
ansible -i your_inventory some_host -m icx_facts
You can debug the ansible_date_time variable to see if an other key suits your needs better than below to create a time stamp. I reconstructed exactly the pattern in your question.
Of course, you need to gather facts for these vars to be available (gather_facts: true on your play meets that requirement).
And here is the sample task (untested, I don't have an ios device available for that)
- name: Backup Config Files
vars:
ip: "{{ ansible_default_ipv4.address }}"
stamp: "{{ ansible_date_time.date }}-{{ ansible_date_time.hour }}:{{ ansible_date_time.minute }}"
prefix: "{{ ip }}-{{ stamp }}"
icx_command:
commands:
- "copy startup-config tftp 192.168.10.5 {{ prefix }}-startup-config.cfg"
- "copy running-config tftp 192.168.10.5 {{ prefix }}-running-config.cfg"

In Emacs how can I use YASnippet to automatically add entry and Clock-in for this entry?

I am trying to create an automation script
such the following steps will happen:
Automatically load my DailyPlan.org file.
For current Date entry.
Insert a new YASnippet subtask entry.
If there is a task being clocked Pause it else ignore.
Start the clock in process for the new task.
This such that I can track in coming calls from Recruiters and have an entry in my DailyPlan.org file and capture all the details from the call or right after the call.
The next step after the call and entering all pertinent information is to clock out and switch back to what I was doing.
I am not sure how to go about creating this. If this should be done in elisp or can it be done just simple using yasnippet ?
Any help and ideas on how to complete this is appreciated!
Thanks!
I was able to get a little further using the following code:
# -*- mode: snippet -*-
# name: Incomming Phone Call
# binding: direct-keybinding
# key: phc
# --
`(org-clock-in)`**** Incomming Call
***** Recruiter Info:
- First Name: $1
- Last Name: $2
- Company: $3
- Email: $9
- Telephone Number: $8
- Account Manager Name:
***** Position Information:
- Title: $4
- Location:
- City: ${5:Austin}
- State: ${6:TX}
- Client Company Name: $7
- Rate: $8
But I am getting the following warning and not sure how to get rid of it:
Warning (yasnippet): ‘Incomming Phone Call’ modified buffer in a backquote expression.
To hide this warning, add (yasnippet backquote-change) to ‘warning-suppress-types’.