Calling a service from a custom button in homeassistant - home-assistant

I'm looking for help with calling a service from a custom button.
I have the following service in developer tools, and calling it works just fine.
service: remote.send_command
data:
device: Livingroom-aircon
command: "On"
target:
entity_id: remote.broadlink_rm4_pro
Hitting the call service button results in my aircon turning on.
In trying to add this function to a dashboard button I have the following
name: Livingroom Aircon
icon: mdi:fan
show_icon: true
type: custom:button-card
tap_action:
action: call-service
service: remote.send_command
data:
device: Livingroom-aircon
command: 'On'
target:
entity_id: remote.broadlink_rm4_pro
entity: remote.broadlink_rm4_pro
Now, when pressing the button I get an error saying
Failed to call service remote/send_command. required key not provided #data['command']
I've done the same thing with a normal button, and the following works...
show_name: true
show_icon: true
type: button
tap_action:
action: call-service
service: remote.send_command
data:
device: Livingroom-aircon
command: 'On'
target:
entity_id: remote.broadlink_rm4_pro
entity: remote.broadlink_rm4_pro
So, how do I do it from the custom button (later I want to add custom graphics/info/animation)

For custom:button-card to work you need to adjust more than just the type of the card. Have a look at the Github page of the project.
You need to replace data with service_data and device with entity_id:
name: Livingroom Aircon
icon: mdi:fan
show_icon: true
type: custom:button-card
tap_action:
action: call-service
service: remote.send_command
service_data: # changed
entity_id: Livingroom-aircon # changed
command: 'On'
target:
entity_id: remote.broadlink_rm4_pro
entity: remote.broadlink_rm4_pro

Related

How to use aws_account parameter from CircleCI in Github Actions

I have this section in one of my CircleCI jobs:
parameters:
aws_account:
type: string
default: '111111111111'
folder:
default: ''
description: The folder the changes will be deployed in
type: string
stack:
default: int
description: Sets the stack the deployment triggers.
type: string
I'm wondering how to move this over to Github Actions because neither parameters or even aws_account on its own is an allowed property for gh actions.

How to configure AWS CDK ApplicationLoadBalancedFargateService to log parsed JSON lines with Firelens and Firebit

When I create an ApplicationLoadBalancedFargateService with a Firelens logdriver, and the application writes JSON lines as the log message, such as when using net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder with Logback, the log messages are displayed in my logging repository (ex. Sumo Logic), as an escaped string, like:
How can I get the log messages to save as parsed JSON?
After scanning CDK source code, browsing several related references (which I will provide links for to help direct appropriate traffic here), and using cdk diff until the only change was to enable json parsing, I was able to make is work as shown in the following code. The key here is the use of the addFirelensLogRouter method and the Firelens config contained therein.
TaskDefinition code does not automatically create a LogRouter container, if the task definition already contains one, which is what allows us to override the default behavior.
protected _createFargateService() {
const logDriver = LogDrivers.firelens({
options: {
Name: 'http',
Host: this._props.containerLogging.endpoint,
URI: this._props.containerLogging.uri,
Port: '443',
tls: 'on',
'tls.verify': 'off',
Format: 'json_lines'
}
});
const fargateService = new ApplicationLoadBalancedFargateService(this, this._props.serviceName, {
cluster: this._accountEnvironmentLookups.getComputeCluster(),
cpu: this._props.cpu, // Default is 256
desiredCount: this._props.desiredCount, // Default is 1
taskImageOptions: {
image: ContainerImage.fromEcrRepository(this._props.serviceRepository, this._props.imageVersion),
environment: this._props.environment,
containerPort: this._props.containerPort,
logDriver
},
memoryLimitMiB: this._props.memoryLimitMiB, // Default is 512
publicLoadBalancer: this._props.publicLoadBalancer, // Default is false
domainName: this._props.domainName,
domainZone: !!this._props.hostedZoneDomain ? HostedZone.fromLookup(this, 'ZoneFromLookup', {
domainName: this._props.hostedZoneDomain
}) : undefined,
certificate: !!this._props.certificateArn ? Certificate.fromCertificateArn(this, 'CertificateFromArn', this._props.certificateArn) : undefined,
serviceName: `${this._props.accountShortName}-${this._props.deploymentEnvironment}-${this._props.serviceName}`,
// The new ARN and resource ID format must be enabled to work with ECS managed tags.
//enableECSManagedTags: true,
//propagateTags: PropagatedTagSource.SERVICE,
// CloudMap properties cannot be set from a stack separate from the stack where the cluster is created.
// see https://github.com/aws/aws-cdk/issues/7825
});
if (this._props.logMessagesAreJsonLines) {
// The default log driver setup doesn't enable json line parsing.
const firelensLogRouter = fargateService.service.taskDefinition.addFirelensLogRouter('log-router', {
// Figured out how get the default fluent bit ECR image from here https://github.com/aws/aws-cdk/blob/60c782fe173449ebf912f509de7db6df89985915/packages/%40aws-cdk/aws-ecs/lib/base/task-definition.ts#L509
image: obtainDefaultFluentBitECRImage(fargateService.service.taskDefinition, fargateService.service.taskDefinition.defaultContainer?.logDriverConfig),
essential: true,
firelensConfig: {
type: FirelensLogRouterType.FLUENTBIT,
options: {
enableECSLogMetadata: true,
configFileType: FirelensConfigFileType.FILE,
// This enables parsing of log messages that are json lines
configFileValue: '/fluent-bit/configs/parse-json.conf'
}
},
memoryReservationMiB: 50,
logging: new AwsLogDriver({streamPrefix: 'firelens'})
});
firelensLogRouter.logDriverConfig;
}
fargateService.targetGroup.configureHealthCheck({
path: this._props.healthUrlPath,
port: this._props.containerPort.toString(),
interval: Duration.seconds(120),
unhealthyThresholdCount: 5
});
const scalableTaskCount = fargateService.service.autoScaleTaskCount({
minCapacity: this._props.desiredCount,
maxCapacity: this._props.maxCapacity
});
scalableTaskCount.scaleOnCpuUtilization(`ScaleOnCpuUtilization${this._props.cpuTargetUtilization}`, {
targetUtilizationPercent: this._props.cpuTargetUtilization
});
scalableTaskCount.scaleOnMemoryUtilization(`ScaleOnMemoryUtilization${this._props.memoryTargetUtilization}`, {
targetUtilizationPercent: this._props.memoryTargetUtilization
});
this.fargateService = fargateService;
}
Resources:
How I first discovered it might be possible.
https://github.com/aws-samples/amazon-ecs-firelens-examples/tree/master/examples/fluent-bit/parse-json
How I discovered it might be possible with CDK https://github.com/aws/aws-cdk/pull/6322
Understanding it from an AWS service standpoint https://docs.aws.amazon.com/AmazonECS/latest/userguide/using_firelens.html
Narrowing in on where it resides in CDK source. https://docs.aws.amazon.com/cdk/api/latest/docs/#aws-cdk_aws-ecs.FirelensLogRouter.html
Eventually I landed here and figured out https://github.com/aws/aws-cdk/blob/60c782fe173449ebf912f509de7db6df89985915/packages/%40aws-cdk/aws-ecs/lib/base/task-definition.ts#L509

Sequelize (4.2.0): Custom validation messages not working with migrations

I am learning how to use sequelize, so far it is a great ORM but I am stuck with the custom validation messages.
I am using the sequelize-cli library to handle migration and I found an issue, custom validation messages don't work if you use the sequelize-cli to create tables, I tried the sequelize.sync method to create the tables and it worked.
Code
This is how I create a field with a custom validation message
Wallet.js
userId: {
type: DataTypes.UUID,
unique: {
name: 'Wallets_userId_unique',
msg: 'This user already have a wallet'
}
},
WalletMigration.js (Not actual migration file name)
userId: {
allowNull: false,
type: Sequelize.UUID,
unique: true,
},
When I tried to create a Wallet with the same userId, I get a Validation error but I should get This user already have a wallet.
The message I am getting is the default message provided by the database because I used unique: true in the migration, If I remove that option the model validation doesn't work.
I want to know what can I do to change this behavior or maybe I am missing something?

Google Deployment Manager - Forwarding Rule (Error)

Help here would be much appreciated, this is something I have been struggling with for awhile. I am trying to deploy a VPN using the Google Deployment Manager. From what I understand I need the following:
VpnTargetGateway
ForwardingRules
VpnTunnels
ReservedIP
I am having trouble with the ForwardingRules. This is where I specify my already created reserved IP address and assign it to my target gateway. Here is my code:
resources:
- name: vmx-forwarding-rules
type: compute.v1.forwardingRule
properties:
region: us-central1
IPAddress: https://www.googleapis.com/compute/v1/projects/{{env["project"] }/regions/us-central1/addresses/vmx-ip
IPProtocol: "ESP"
target: https://www.googleapis.com/compute/v1/projects/{{ env["project"] }/regions/us-central1/targetVpnGateways/vmx-vpn-gateway
Here is the error I receive:
message: u"Unexpected response from resource of type compute.v1.forwardingRule: 400 {statusMessage=Bad Request, errors=[{message=Invalid value for field 'resource': ''. A reserved IP should be specified for forwarding rule with target type TARGET_VPN_GATEWAY, domain=global, reason=invalid}]}">]>
Does anyone have any experience with this or know a better location to find help for Deployment Manager?
Thanks
Try this in your YAML configuration:
resources:
- name: vmx-ip
type: compute.v1.address
properties:
region: us-central1
- name: vmx-forwarding-rules
type: compute.v1.forwardingRule
properties:
region: us-central1
IPAddress: $(ref.vmx-ip.address)
IPProtocol: "ESP"
target: https://www.googleapis.com/compute/v1/projects/{{ env["project"] }}/regions/us-central1/targetVpnGateways/vmx-vpn-gateway

Symfony 2 - UrlGenerator::doGenerate is called before listener

I want to add to the context a parameter, so when login is called I can use it in the route (similar to _locale).
I can add this piece of code in HttpUtils.php (as resetLocale), but i don't find it very clean. The reason I need it is the firewall redirection to the login controller, which I would like to have in its route a customized parameter.
My problem is that my listener is called after UrlGenerator::doGenerate is called, so I get a MissingMandatoryParametersException.
Here is my config.yml relevant code:
services:
mycompany.demobundle.listener.request:
class: MyCompany\DemoBundle\RequestListener
arguments: [#router, #security.context]
tags:
- { name: kernel.event_listener, event: kernel.request, method: onKernelRequest }
Any idea???
Have you tried manipulating the priority option?
tags:
- { name: kernel.event_listener, event: kernel.request, priority: 0, method: onKernelRequest }
Yep, you should use priority option it can be from -255 to 255